annotate src/audio/SDL_audiotypecvt.c @ 4900:69d9db65f248

Merged the Windows custom window system hooks into the union used by X11. Added Cocoa custom window system hooks
author Sam Lantinga <slouken@libsdl.org>
date Mon, 27 Sep 2010 01:24:05 -0700
parents 8c9cbb623d55
children b530ef003506
rev   line source
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1 /* DO NOT EDIT! This file is generated by sdlgenaudiocvt.pl */
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 /*
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
4 Copyright (C) 1997-2010 Sam Lantinga
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 Lesser General Public License for more details.
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 You should have received a copy of the GNU Lesser General Public
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 License along with this library; if not, write to the Free Software
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 Sam Lantinga
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 slouken@libsdl.org
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 */
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 #include "SDL_config.h"
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 #include "SDL_audio.h"
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #include "SDL_audio_c.h"
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
28 #ifndef DEBUG_CONVERT
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
29 #define DEBUG_CONVERT 0
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
30 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
31
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
32
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
33 /* If you can guarantee your data and need space, you can eliminate code... */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
34
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
35 /* Just build the arbitrary resamplers if you're saving code space. */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
36 #ifndef LESS_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
37 #define LESS_RESAMPLERS 0
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
38 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
39
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
40 /* Don't build any resamplers if you're REALLY saving code space. */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
41 #ifndef NO_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
42 #define NO_RESAMPLERS 0
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
43 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
44
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
45 /* Don't build any type converters if you're saving code space. */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
46 #ifndef NO_CONVERTERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
47 #define NO_CONVERTERS 0
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
48 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
49
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
50
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
51 /* *INDENT-OFF* */
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #define DIVBY127 0.0078740157480315f
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #define DIVBY32767 3.05185094759972e-05f
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 #define DIVBY2147483647 4.6566128752458e-10f
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
57 #if !NO_CONVERTERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
58
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 SDL_Convert_U8_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
66 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 src = (const Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 const Sint8 val = ((*src) ^ 0x80);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
78 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 SDL_Convert_U8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
89 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
93 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
94 dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 const Uint16 val = (((Uint16) *src) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
102 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 SDL_Convert_U8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
113 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
117 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
118 dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
126 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 SDL_Convert_U8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
137 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
141 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
142 dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 const Uint16 val = (((Uint16) *src) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
150 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 SDL_Convert_U8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
161 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
165 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
166 dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 const Sint16 val = (((Sint16) ((*src) ^ 0x80)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
174 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 SDL_Convert_U8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
185 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
189 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
190 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
198 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 SDL_Convert_U8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
209 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
213 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
214 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 const Sint32 val = (((Sint32) ((*src) ^ 0x80)) << 24);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
222 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 SDL_Convert_U8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
233 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
237 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
238 dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
240 const float val = ((((float) *src) * DIVBY127) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
246 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 SDL_Convert_U8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
257 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 fprintf(stderr, "Converting AUDIO_U8 to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
261 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
262 dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
264 const float val = ((((float) *src) * DIVBY127) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
270 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 SDL_Convert_S8_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
281 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 src = (const Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 const Uint8 val = ((((Sint8) *src)) ^ 0x80);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
293 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 SDL_Convert_S8_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
304 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
308 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
309 dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
317 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 SDL_Convert_S8_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
328 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
332 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
333 dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
341 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 SDL_Convert_S8_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
352 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
356 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
357 dst = ((Uint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 const Uint16 val = (((Uint16) ((((Sint8) *src)) ^ 0x80)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
365 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 SDL_Convert_S8_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
376 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
380 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
381 dst = ((Sint16 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 const Sint16 val = (((Sint16) ((Sint8) *src)) << 8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
389 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 SDL_Convert_S8_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
400 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
404 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
405 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
413 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 SDL_Convert_S8_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
424 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
428 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
429 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 const Sint32 val = (((Sint32) ((Sint8) *src)) << 24);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
437 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 SDL_Convert_S8_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
448 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
452 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
453 dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455 const float val = (((float) ((Sint8) *src)) * DIVBY127);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
461 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466 SDL_Convert_S8_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 const Uint8 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
472 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 fprintf(stderr, "Converting AUDIO_S8 to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
476 src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
477 dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 for (i = cvt->len_cvt / sizeof (Uint8); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 const float val = (((float) ((Sint8) *src)) * DIVBY127);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 cvt->len_cvt *= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
485 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 SDL_Convert_U16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
496 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 const Uint8 val = ((Uint8) (SDL_SwapLE16(*src) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
509 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 SDL_Convert_U16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
520 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 const Sint8 val = ((Sint8) (((SDL_SwapLE16(*src)) ^ 0x8000) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
533 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 SDL_Convert_U16LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
544 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551 const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
556 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 SDL_Convert_U16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
567 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 const Uint16 val = SDL_SwapLE16(*src);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
579 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 SDL_Convert_U16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
590 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
594 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597 const Sint16 val = ((SDL_SwapLE16(*src)) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
602 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
606 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607 SDL_Convert_U16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
609 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
613 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
615 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
616
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
617 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
618 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620 const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
621 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
622 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
626 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
627 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
630 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631 SDL_Convert_U16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
633 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
634 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
635 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
636
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
637 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
638 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
639 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
640
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
641 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
642 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
643 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
644 const Sint32 val = (((Sint32) ((SDL_SwapLE16(*src)) ^ 0x8000)) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
645 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
650 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
653
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
654 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
655 SDL_Convert_U16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
657 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
659 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
660
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
661 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
662 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
663 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
664
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
665 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
666 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
667 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
668 const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
669 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
670 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
671
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
672 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
673 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
674 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
675 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
676 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
677
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
678 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
679 SDL_Convert_U16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
680 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
681 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
682 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
683 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
684
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
685 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
686 fprintf(stderr, "Converting AUDIO_U16LSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
687 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
688
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
689 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
690 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
691 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
692 const float val = ((((float) SDL_SwapLE16(*src)) * DIVBY32767) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
693 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
694 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
695
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
696 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
697 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
698 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
699 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
700 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
701
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
702 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
703 SDL_Convert_S16LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
704 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
705 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
706 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
707 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
708
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
709 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
710 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
711 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
712
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
713 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
714 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
715 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
716 const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
717 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
718 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
719
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
720 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
721 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
722 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
723 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
724 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
725
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
726 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
727 SDL_Convert_S16LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
728 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
729 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
730 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
731 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
732
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
733 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
734 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
735 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
736
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
737 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
738 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
739 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
740 const Sint8 val = ((Sint8) (((Sint16) SDL_SwapLE16(*src)) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
741 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
742 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
743
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
744 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
745 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
746 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
747 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
748 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
749
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
751 SDL_Convert_S16LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
752 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
753 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
754 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
755 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
756
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
757 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
758 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
759 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
760
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
761 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
762 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
763 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
764 const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
765 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
766 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
767
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
768 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
769 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
770 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
771 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
772
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
773 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
774 SDL_Convert_S16LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
775 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
776 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
777 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
778 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
779
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
780 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
781 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
782 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
783
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
784 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
785 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
786 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
787 const Uint16 val = ((((Sint16) SDL_SwapLE16(*src))) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
788 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
789 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
790
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
791 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
792 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
793 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
794 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
795
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
796 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
797 SDL_Convert_S16LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
798 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
799 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
800 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
801 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
802
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
803 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
804 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
805 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
806
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
807 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
808 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
809 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
810 const Sint16 val = ((Sint16) SDL_SwapLE16(*src));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
811 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
812 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
813
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
814 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
815 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
816 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
817 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
818
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
819 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
820 SDL_Convert_S16LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
821 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
822 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
823 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
824 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
825
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
826 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
827 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
828 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
829
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
830 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
831 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
832 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
833 const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
834 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
835 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
836
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
837 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
838 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
839 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
840 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
841 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
842
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
843 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
844 SDL_Convert_S16LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
845 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
846 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
847 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
848 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
849
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
850 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
851 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
852 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
853
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
854 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
855 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
856 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
857 const Sint32 val = (((Sint32) ((Sint16) SDL_SwapLE16(*src))) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
858 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
859 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
860
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
861 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
862 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
863 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
864 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
865 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
866
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
867 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
868 SDL_Convert_S16LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
869 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
870 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
871 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
872 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
873
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
874 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
875 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
876 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
877
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
878 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
879 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
880 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
881 const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
882 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
883 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
884
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
885 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
886 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
887 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
888 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
889 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
890
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
891 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
892 SDL_Convert_S16LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
893 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
894 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
895 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
896 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
897
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
898 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
899 fprintf(stderr, "Converting AUDIO_S16LSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
900 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
901
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
902 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
903 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
904 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
905 const float val = (((float) ((Sint16) SDL_SwapLE16(*src))) * DIVBY32767);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
906 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
907 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
908
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
909 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
910 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
911 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
912 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
913 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
914
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
915 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
916 SDL_Convert_U16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
917 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
918 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
919 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
920 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
921
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
922 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
923 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
924 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
925
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
926 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
927 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
928 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
929 const Uint8 val = ((Uint8) (SDL_SwapBE16(*src) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
930 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
931 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
932
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
933 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
934 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
935 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
936 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
937 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
938
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
939 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
940 SDL_Convert_U16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
941 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
942 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
943 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
944 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
945
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
946 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
947 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
948 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
949
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
950 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
951 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
952 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
953 const Sint8 val = ((Sint8) (((SDL_SwapBE16(*src)) ^ 0x8000) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
954 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
955 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
956
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
957 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
958 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
959 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
960 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
961 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
962
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
963 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
964 SDL_Convert_U16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
965 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
966 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
967 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
968 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
969
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
970 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
971 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
972 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
973
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
974 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
975 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
976 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
977 const Uint16 val = SDL_SwapBE16(*src);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
978 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
979 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
980
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
981 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
982 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
983 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
984 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
985
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
986 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
987 SDL_Convert_U16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
988 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
989 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
990 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
991 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
992
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
993 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
994 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
995 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
996
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
997 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
998 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
999 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1000 const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1001 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1002 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1003
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1004 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1005 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1006 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1007 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1008
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1009 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1010 SDL_Convert_U16MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1011 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1012 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1013 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1014 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1015
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1016 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1017 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1018 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1019
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1020 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1021 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1022 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1023 const Sint16 val = ((SDL_SwapBE16(*src)) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1024 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1025 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1026
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1027 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1028 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1029 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1030 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1031
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1032 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1033 SDL_Convert_U16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1034 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1035 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1036 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1037 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1038
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1039 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1040 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1041 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1042
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1043 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1044 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1045 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1046 const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1047 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1048 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1049
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1050 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1051 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1052 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1053 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1054 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1055
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1056 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1057 SDL_Convert_U16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1058 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1059 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1060 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1061 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1062
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1063 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1064 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1065 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1066
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1067 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1068 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1069 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1070 const Sint32 val = (((Sint32) ((SDL_SwapBE16(*src)) ^ 0x8000)) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1071 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1072 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1073
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1074 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1075 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1076 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1077 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1078 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1079
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1080 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1081 SDL_Convert_U16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1082 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1083 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1084 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1085 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1086
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1087 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1088 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1089 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1090
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1091 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1092 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1093 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1094 const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1095 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1096 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1097
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1098 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1099 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1100 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1101 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1102 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1103
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1104 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1105 SDL_Convert_U16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1106 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1107 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1108 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1109 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1110
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1111 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1112 fprintf(stderr, "Converting AUDIO_U16MSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1113 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1114
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1115 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1116 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1117 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1118 const float val = ((((float) SDL_SwapBE16(*src)) * DIVBY32767) - 1.0f);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1119 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1120 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1121
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1122 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1123 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1124 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1125 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1126 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1127
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1128 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1129 SDL_Convert_S16MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1130 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1131 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1132 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1133 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1134
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1135 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1136 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1137 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1138
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1139 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1140 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1141 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1142 const Uint8 val = ((Uint8) (((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1143 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1144 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1145
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1146 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1147 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1148 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1149 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1150 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1151
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1152 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1153 SDL_Convert_S16MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1154 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1155 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1156 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1157 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1158
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1159 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1160 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1161 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1162
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1163 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1164 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1165 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1166 const Sint8 val = ((Sint8) (((Sint16) SDL_SwapBE16(*src)) >> 8));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1167 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1168 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1169
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1170 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1171 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1172 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1173 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1174 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1175
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1176 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1177 SDL_Convert_S16MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1178 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1179 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1180 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1181 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1182
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1183 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1184 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1185 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1186
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1187 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1188 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1189 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1190 const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1191 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1192 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1193
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1194 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1195 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1196 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1197 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1198
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1199 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1200 SDL_Convert_S16MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1201 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1202 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1203 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1204 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1205
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1206 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1207 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1208 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1209
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1210 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1211 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1212 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1213 const Sint16 val = ((Sint16) SDL_SwapBE16(*src));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1214 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1215 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1216
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1217 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1218 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1219 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1220 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1221
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1222 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1223 SDL_Convert_S16MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1224 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1225 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1226 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1227 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1228
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1229 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1230 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1231 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1232
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1233 src = (const Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1234 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1235 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1236 const Uint16 val = ((((Sint16) SDL_SwapBE16(*src))) ^ 0x8000);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1237 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1238 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1239
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1240 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1241 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1242 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1243 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1244
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1245 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1246 SDL_Convert_S16MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1247 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1248 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1249 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1250 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1251
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1252 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1253 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1254 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1255
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1256 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1257 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1258 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1259 const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1260 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1261 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1262
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1263 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1264 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1265 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1266 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1267 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1268
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1269 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1270 SDL_Convert_S16MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1271 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1272 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1273 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1274 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1275
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1276 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1277 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1278 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1279
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1280 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1281 dst = ((Sint32 *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1282 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1283 const Sint32 val = (((Sint32) ((Sint16) SDL_SwapBE16(*src))) << 16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1284 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1285 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1286
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1287 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1288 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1289 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1290 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1291 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1292
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1293 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1294 SDL_Convert_S16MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1295 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1296 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1297 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1298 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1299
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1300 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1301 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1302 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1303
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1304 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1305 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1306 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1307 const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1308 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1309 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1310
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1311 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1312 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1313 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1314 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1315 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1316
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1317 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1318 SDL_Convert_S16MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1319 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1320 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1321 const Uint16 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1322 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1323
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1324 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1325 fprintf(stderr, "Converting AUDIO_S16MSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1326 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1327
2956
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1328 src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
1210d5a28e16 Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents: 2955
diff changeset
1329 dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1330 for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1331 const float val = (((float) ((Sint16) SDL_SwapBE16(*src))) * DIVBY32767);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1332 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1333 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1334
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1335 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1336 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1337 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1338 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1339 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1340
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1341 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1342 SDL_Convert_S32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1343 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1344 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1345 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1346 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1347
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1348 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1349 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1350 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1351
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1352 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1353 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1354 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1355 const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 24));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1356 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1357 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1358
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1359 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1360 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1361 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1362 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1363 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1364
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1365 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1366 SDL_Convert_S32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1367 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1368 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1369 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1370 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1371
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1372 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1373 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1374 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1375
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1376 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1377 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1378 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1379 const Sint8 val = ((Sint8) (((Sint32) SDL_SwapLE32(*src)) >> 24));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1380 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1381 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1382
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1383 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1384 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1385 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1386 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1387 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1388
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1389 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1390 SDL_Convert_S32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1391 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1392 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1393 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1394 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1395
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1396 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1397 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1398 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1399
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1400 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1401 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1402 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1403 const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1404 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1405 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1406
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1407 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1408 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1409 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1410 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1411 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1412
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1413 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1414 SDL_Convert_S32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1415 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1416 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1417 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1418 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1419
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1420 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1421 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1422 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1423
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1424 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1425 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1426 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1427 const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1428 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1429 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1430
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1431 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1432 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1433 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1434 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1435 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1436
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1437 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1438 SDL_Convert_S32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1439 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1440 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1441 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1442 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1443
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1444 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1445 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1446 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1447
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1448 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1449 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1450 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1451 const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapLE32(*src))) ^ 0x80000000) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1452 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1453 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1454
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1455 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1456 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1457 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1458 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1459 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1460
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1461 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1462 SDL_Convert_S32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1463 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1464 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1465 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1466 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1467
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1468 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1469 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1470 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1471
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1472 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1473 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1474 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1475 const Sint16 val = ((Sint16) (((Sint32) SDL_SwapLE32(*src)) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1476 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1477 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1478
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1479 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1480 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1481 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1482 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1483 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1484
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1485 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1486 SDL_Convert_S32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1487 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1488 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1489 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1490 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1491
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1492 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1493 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1494 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1495
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1496 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1497 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1498 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1499 const Sint32 val = ((Sint32) SDL_SwapLE32(*src));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1500 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1501 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1502
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1503 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1504 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1505 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1506 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1507
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1508 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1509 SDL_Convert_S32LSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1510 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1511 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1512 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1513 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1514
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1515 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1516 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1517 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1518
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1519 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1520 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1521 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1522 const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1523 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1524 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1525
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1526 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1527 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1528 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1529 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1530
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1531 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1532 SDL_Convert_S32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1533 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1534 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1535 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1536 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1537
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1538 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1539 fprintf(stderr, "Converting AUDIO_S32LSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1540 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1541
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1542 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1543 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1544 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1545 const float val = (((float) ((Sint32) SDL_SwapLE32(*src))) * DIVBY2147483647);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1546 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1547 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1548
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1549 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1550 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1551 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1552 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1553
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1554 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1555 SDL_Convert_S32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1556 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1557 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1558 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1559 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1560
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1561 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1562 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1563 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1564
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1565 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1566 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1567 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1568 const Uint8 val = ((Uint8) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 24));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1569 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1570 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1571
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1572 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1573 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1574 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1575 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1576 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1577
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1578 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1579 SDL_Convert_S32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1580 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1581 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1582 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1583 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1584
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1585 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1586 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1587 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1588
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1589 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1590 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1591 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1592 const Sint8 val = ((Sint8) (((Sint32) SDL_SwapBE32(*src)) >> 24));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1593 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1594 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1595
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1596 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1597 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1598 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1599 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1600 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1601
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1602 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1603 SDL_Convert_S32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1604 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1605 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1606 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1607 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1608
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1609 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1610 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1611 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1612
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1613 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1614 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1615 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1616 const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1617 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1618 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1619
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1620 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1621 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1622 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1623 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1624 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1625
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1626 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1627 SDL_Convert_S32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1628 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1629 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1630 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1631 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1632
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1633 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1634 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1635 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1636
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1637 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1638 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1639 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1640 const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1641 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1642 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1643
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1644 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1645 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1646 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1647 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1648 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1649
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1650 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1651 SDL_Convert_S32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1652 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1653 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1654 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1655 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1656
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1657 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1658 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1659 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1660
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1661 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1662 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1663 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1664 const Uint16 val = ((Uint16) (((((Sint32) SDL_SwapBE32(*src))) ^ 0x80000000) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1665 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1666 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1667
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1668 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1669 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1670 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1671 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1672 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1673
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1674 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1675 SDL_Convert_S32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1676 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1677 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1678 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1679 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1680
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1681 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1682 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1683 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1684
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1685 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1686 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1687 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1688 const Sint16 val = ((Sint16) (((Sint32) SDL_SwapBE32(*src)) >> 16));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1689 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1690 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1691
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1692 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1693 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1694 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1695 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1696 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1697
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1698 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1699 SDL_Convert_S32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1700 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1701 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1702 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1703 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1704
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1705 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1706 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1707 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1708
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1709 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1710 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1711 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1712 const Sint32 val = ((Sint32) SDL_SwapBE32(*src));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1713 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1714 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1715
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1716 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1717 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1718 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1719 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1720
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1721 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1722 SDL_Convert_S32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1723 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1724 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1725 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1726 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1727
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1728 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1729 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1730 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1731
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1732 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1733 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1734 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1735 const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1736 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1737 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1738
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1739 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1740 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1741 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1742 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1743
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1744 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1745 SDL_Convert_S32MSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1746 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1747 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1748 const Uint32 *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1749 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1750
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1751 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1752 fprintf(stderr, "Converting AUDIO_S32MSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1753 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1754
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1755 src = (const Uint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1756 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1757 for (i = cvt->len_cvt / sizeof (Uint32); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1758 const float val = (((float) ((Sint32) SDL_SwapBE32(*src))) * DIVBY2147483647);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1759 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1760 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1761
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1762 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1763 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1764 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1765 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1766
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1767 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1768 SDL_Convert_F32LSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1769 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1770 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1771 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1772 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1773
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1774 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1775 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1776 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1777
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1778 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1779 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1780 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1781 const Uint8 val = ((Uint8) ((SDL_SwapFloatLE(*src) + 1.0f) * 127.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1782 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1783 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1784
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1785 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1786 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1787 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1788 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1789 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1790
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1791 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1792 SDL_Convert_F32LSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1793 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1794 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1795 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1796 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1797
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1798 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1799 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1800 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1801
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1802 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1803 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1804 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1805 const Sint8 val = ((Sint8) (SDL_SwapFloatLE(*src) * 127.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1806 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1807 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1808
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1809 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1810 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1811 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1812 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1813 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1814
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1815 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1816 SDL_Convert_F32LSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1817 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1818 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1819 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1820 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1821
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1822 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1823 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1824 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1825
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1826 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1827 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1828 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1829 const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1830 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1831 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1832
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1833 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1834 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1835 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1836 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1837 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1838
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1839 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1840 SDL_Convert_F32LSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1841 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1842 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1843 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1844 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1845
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1846 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1847 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1848 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1849
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1850 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1851 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1852 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1853 const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1854 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1855 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1856
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1857 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1858 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1859 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1860 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1861 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1862
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1863 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1864 SDL_Convert_F32LSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1865 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1866 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1867 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1868 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1869
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1870 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1871 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1872 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1873
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1874 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1875 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1876 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1877 const Uint16 val = ((Uint16) ((SDL_SwapFloatLE(*src) + 1.0f) * 32767.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1878 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1879 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1880
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1881 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1882 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1883 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1884 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1885 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1886
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1887 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1888 SDL_Convert_F32LSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1889 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1890 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1891 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1892 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1893
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1894 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1895 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1896 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1897
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1898 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1899 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1900 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1901 const Sint16 val = ((Sint16) (SDL_SwapFloatLE(*src) * 32767.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1902 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1903 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1904
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1905 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1906 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1907 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1908 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1909 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1910
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1911 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1912 SDL_Convert_F32LSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1913 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1914 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1915 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1916 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1917
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1918 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1919 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1920 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1921
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1922 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1923 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1924 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1925 const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1926 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1927 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1928
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1929 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1930 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1931 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1932 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1933
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1934 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1935 SDL_Convert_F32LSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1936 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1937 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1938 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1939 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1940
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1941 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1942 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1943 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1944
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1945 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1946 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1947 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1948 const Sint32 val = ((Sint32) (SDL_SwapFloatLE(*src) * 2147483647.0));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1949 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1950 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1951
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1952 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1953 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1954 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1955 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1956
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1957 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1958 SDL_Convert_F32LSB_to_F32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1959 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1960 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1961 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1962 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1963
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1964 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1965 fprintf(stderr, "Converting AUDIO_F32LSB to AUDIO_F32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1966 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1967
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1968 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1969 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1970 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1971 const float val = SDL_SwapFloatLE(*src);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1972 *dst = SDL_SwapFloatBE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1973 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1974
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1975 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
1976 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1977 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1978 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1979
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1980 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1981 SDL_Convert_F32MSB_to_U8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1982 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1983 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1984 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1985 Uint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1986
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
1987 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1988 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1989 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1990
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1991 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1992 dst = (Uint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1993 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
1994 const Uint8 val = ((Uint8) ((SDL_SwapFloatBE(*src) + 1.0f) * 127.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1995 *dst = val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1996 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1997
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1998 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1999 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2000 cvt->filters[cvt->filter_index] (cvt, AUDIO_U8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2001 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2002 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2003
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2004 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2005 SDL_Convert_F32MSB_to_S8(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2006 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2007 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2008 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2009 Sint8 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2010
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2011 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2012 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S8.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2013 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2014
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2015 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2016 dst = (Sint8 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2017 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2018 const Sint8 val = ((Sint8) (SDL_SwapFloatBE(*src) * 127.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2019 *dst = ((Sint8) val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2020 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2021
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2022 cvt->len_cvt /= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2023 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2024 cvt->filters[cvt->filter_index] (cvt, AUDIO_S8);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2025 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2026 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2027
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2028 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2029 SDL_Convert_F32MSB_to_U16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2030 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2031 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2032 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2033 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2034
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2035 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2036 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2037 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2038
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2039 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2040 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2041 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
2042 const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2043 *dst = SDL_SwapLE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2044 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2045
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2046 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2047 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2048 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2049 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2050 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2051
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2052 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2053 SDL_Convert_F32MSB_to_S16LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2054 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2055 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2056 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2057 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2058
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2059 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2060 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2061 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2062
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2063 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2064 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2065 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2066 const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2067 *dst = ((Sint16) SDL_SwapLE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2068 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2069
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2070 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2071 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2072 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2073 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2074 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2075
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2076 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2077 SDL_Convert_F32MSB_to_U16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2078 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2079 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2080 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2081 Uint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2082
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2083 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2084 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_U16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2085 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2086
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2087 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2088 dst = (Uint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2089 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
2090 const Uint16 val = ((Uint16) ((SDL_SwapFloatBE(*src) + 1.0f) * 32767.0f));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2091 *dst = SDL_SwapBE16(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2092 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2093
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2094 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2095 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2096 cvt->filters[cvt->filter_index] (cvt, AUDIO_U16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2097 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2098 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2099
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2100 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2101 SDL_Convert_F32MSB_to_S16MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2102 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2103 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2104 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2105 Sint16 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2106
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2107 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2108 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S16MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2109 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2110
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2111 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2112 dst = (Sint16 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2113 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2114 const Sint16 val = ((Sint16) (SDL_SwapFloatBE(*src) * 32767.0f));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2115 *dst = ((Sint16) SDL_SwapBE16(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2116 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2117
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2118 cvt->len_cvt /= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2119 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2120 cvt->filters[cvt->filter_index] (cvt, AUDIO_S16MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2121 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2122 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2123
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2124 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2125 SDL_Convert_F32MSB_to_S32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2126 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2127 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2128 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2129 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2130
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2131 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2132 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2133 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2134
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2135 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2136 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2137 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2138 const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2139 *dst = ((Sint32) SDL_SwapLE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2140 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2141
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2142 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2143 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2144 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2145 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2146
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2147 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2148 SDL_Convert_F32MSB_to_S32MSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2149 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2150 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2151 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2152 Sint32 *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2153
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2154 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2155 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_S32MSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2156 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2157
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2158 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2159 dst = (Sint32 *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2160 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2161 const Sint32 val = ((Sint32) (SDL_SwapFloatBE(*src) * 2147483647.0));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2162 *dst = ((Sint32) SDL_SwapBE32(val));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2163 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2164
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2165 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2166 cvt->filters[cvt->filter_index] (cvt, AUDIO_S32MSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2167 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2168 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2169
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2170 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2171 SDL_Convert_F32MSB_to_F32LSB(SDL_AudioCVT * cvt, SDL_AudioFormat format)
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2172 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2173 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2174 const float *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2175 float *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2176
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2177 #if DEBUG_CONVERT
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2178 fprintf(stderr, "Converting AUDIO_F32MSB to AUDIO_F32LSB.\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2179 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2180
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2181 src = (const float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2182 dst = (float *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2183 for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2184 const float val = SDL_SwapFloatBE(*src);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2185 *dst = SDL_SwapFloatLE(val);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2186 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2187
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2188 if (cvt->filters[++cvt->filter_index]) {
2955
2692999d5271 Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
2189 cvt->filters[cvt->filter_index] (cvt, AUDIO_F32LSB);
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2190 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2191 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2192
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2193 #endif /* !NO_CONVERTERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2194
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2195
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2196 const SDL_AudioTypeFilters sdl_audio_type_filters[] =
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2197 {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2198 #if !NO_CONVERTERS
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2199 { AUDIO_U8, AUDIO_S8, SDL_Convert_U8_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2200 { AUDIO_U8, AUDIO_U16LSB, SDL_Convert_U8_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2201 { AUDIO_U8, AUDIO_S16LSB, SDL_Convert_U8_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2202 { AUDIO_U8, AUDIO_U16MSB, SDL_Convert_U8_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2203 { AUDIO_U8, AUDIO_S16MSB, SDL_Convert_U8_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2204 { AUDIO_U8, AUDIO_S32LSB, SDL_Convert_U8_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2205 { AUDIO_U8, AUDIO_S32MSB, SDL_Convert_U8_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2206 { AUDIO_U8, AUDIO_F32LSB, SDL_Convert_U8_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2207 { AUDIO_U8, AUDIO_F32MSB, SDL_Convert_U8_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2208 { AUDIO_S8, AUDIO_U8, SDL_Convert_S8_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2209 { AUDIO_S8, AUDIO_U16LSB, SDL_Convert_S8_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2210 { AUDIO_S8, AUDIO_S16LSB, SDL_Convert_S8_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2211 { AUDIO_S8, AUDIO_U16MSB, SDL_Convert_S8_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2212 { AUDIO_S8, AUDIO_S16MSB, SDL_Convert_S8_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2213 { AUDIO_S8, AUDIO_S32LSB, SDL_Convert_S8_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2214 { AUDIO_S8, AUDIO_S32MSB, SDL_Convert_S8_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2215 { AUDIO_S8, AUDIO_F32LSB, SDL_Convert_S8_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2216 { AUDIO_S8, AUDIO_F32MSB, SDL_Convert_S8_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2217 { AUDIO_U16LSB, AUDIO_U8, SDL_Convert_U16LSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2218 { AUDIO_U16LSB, AUDIO_S8, SDL_Convert_U16LSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2219 { AUDIO_U16LSB, AUDIO_S16LSB, SDL_Convert_U16LSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2220 { AUDIO_U16LSB, AUDIO_U16MSB, SDL_Convert_U16LSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2221 { AUDIO_U16LSB, AUDIO_S16MSB, SDL_Convert_U16LSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2222 { AUDIO_U16LSB, AUDIO_S32LSB, SDL_Convert_U16LSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2223 { AUDIO_U16LSB, AUDIO_S32MSB, SDL_Convert_U16LSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2224 { AUDIO_U16LSB, AUDIO_F32LSB, SDL_Convert_U16LSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2225 { AUDIO_U16LSB, AUDIO_F32MSB, SDL_Convert_U16LSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2226 { AUDIO_S16LSB, AUDIO_U8, SDL_Convert_S16LSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2227 { AUDIO_S16LSB, AUDIO_S8, SDL_Convert_S16LSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2228 { AUDIO_S16LSB, AUDIO_U16LSB, SDL_Convert_S16LSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2229 { AUDIO_S16LSB, AUDIO_U16MSB, SDL_Convert_S16LSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2230 { AUDIO_S16LSB, AUDIO_S16MSB, SDL_Convert_S16LSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2231 { AUDIO_S16LSB, AUDIO_S32LSB, SDL_Convert_S16LSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2232 { AUDIO_S16LSB, AUDIO_S32MSB, SDL_Convert_S16LSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2233 { AUDIO_S16LSB, AUDIO_F32LSB, SDL_Convert_S16LSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2234 { AUDIO_S16LSB, AUDIO_F32MSB, SDL_Convert_S16LSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2235 { AUDIO_U16MSB, AUDIO_U8, SDL_Convert_U16MSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2236 { AUDIO_U16MSB, AUDIO_S8, SDL_Convert_U16MSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2237 { AUDIO_U16MSB, AUDIO_U16LSB, SDL_Convert_U16MSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2238 { AUDIO_U16MSB, AUDIO_S16LSB, SDL_Convert_U16MSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2239 { AUDIO_U16MSB, AUDIO_S16MSB, SDL_Convert_U16MSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2240 { AUDIO_U16MSB, AUDIO_S32LSB, SDL_Convert_U16MSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2241 { AUDIO_U16MSB, AUDIO_S32MSB, SDL_Convert_U16MSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2242 { AUDIO_U16MSB, AUDIO_F32LSB, SDL_Convert_U16MSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2243 { AUDIO_U16MSB, AUDIO_F32MSB, SDL_Convert_U16MSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2244 { AUDIO_S16MSB, AUDIO_U8, SDL_Convert_S16MSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2245 { AUDIO_S16MSB, AUDIO_S8, SDL_Convert_S16MSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2246 { AUDIO_S16MSB, AUDIO_U16LSB, SDL_Convert_S16MSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2247 { AUDIO_S16MSB, AUDIO_S16LSB, SDL_Convert_S16MSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2248 { AUDIO_S16MSB, AUDIO_U16MSB, SDL_Convert_S16MSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2249 { AUDIO_S16MSB, AUDIO_S32LSB, SDL_Convert_S16MSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2250 { AUDIO_S16MSB, AUDIO_S32MSB, SDL_Convert_S16MSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2251 { AUDIO_S16MSB, AUDIO_F32LSB, SDL_Convert_S16MSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2252 { AUDIO_S16MSB, AUDIO_F32MSB, SDL_Convert_S16MSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2253 { AUDIO_S32LSB, AUDIO_U8, SDL_Convert_S32LSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2254 { AUDIO_S32LSB, AUDIO_S8, SDL_Convert_S32LSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2255 { AUDIO_S32LSB, AUDIO_U16LSB, SDL_Convert_S32LSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2256 { AUDIO_S32LSB, AUDIO_S16LSB, SDL_Convert_S32LSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2257 { AUDIO_S32LSB, AUDIO_U16MSB, SDL_Convert_S32LSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2258 { AUDIO_S32LSB, AUDIO_S16MSB, SDL_Convert_S32LSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2259 { AUDIO_S32LSB, AUDIO_S32MSB, SDL_Convert_S32LSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2260 { AUDIO_S32LSB, AUDIO_F32LSB, SDL_Convert_S32LSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2261 { AUDIO_S32LSB, AUDIO_F32MSB, SDL_Convert_S32LSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2262 { AUDIO_S32MSB, AUDIO_U8, SDL_Convert_S32MSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2263 { AUDIO_S32MSB, AUDIO_S8, SDL_Convert_S32MSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2264 { AUDIO_S32MSB, AUDIO_U16LSB, SDL_Convert_S32MSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2265 { AUDIO_S32MSB, AUDIO_S16LSB, SDL_Convert_S32MSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2266 { AUDIO_S32MSB, AUDIO_U16MSB, SDL_Convert_S32MSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2267 { AUDIO_S32MSB, AUDIO_S16MSB, SDL_Convert_S32MSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2268 { AUDIO_S32MSB, AUDIO_S32LSB, SDL_Convert_S32MSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2269 { AUDIO_S32MSB, AUDIO_F32LSB, SDL_Convert_S32MSB_to_F32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2270 { AUDIO_S32MSB, AUDIO_F32MSB, SDL_Convert_S32MSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2271 { AUDIO_F32LSB, AUDIO_U8, SDL_Convert_F32LSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2272 { AUDIO_F32LSB, AUDIO_S8, SDL_Convert_F32LSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2273 { AUDIO_F32LSB, AUDIO_U16LSB, SDL_Convert_F32LSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2274 { AUDIO_F32LSB, AUDIO_S16LSB, SDL_Convert_F32LSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2275 { AUDIO_F32LSB, AUDIO_U16MSB, SDL_Convert_F32LSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2276 { AUDIO_F32LSB, AUDIO_S16MSB, SDL_Convert_F32LSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2277 { AUDIO_F32LSB, AUDIO_S32LSB, SDL_Convert_F32LSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2278 { AUDIO_F32LSB, AUDIO_S32MSB, SDL_Convert_F32LSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2279 { AUDIO_F32LSB, AUDIO_F32MSB, SDL_Convert_F32LSB_to_F32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2280 { AUDIO_F32MSB, AUDIO_U8, SDL_Convert_F32MSB_to_U8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2281 { AUDIO_F32MSB, AUDIO_S8, SDL_Convert_F32MSB_to_S8 },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2282 { AUDIO_F32MSB, AUDIO_U16LSB, SDL_Convert_F32MSB_to_U16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2283 { AUDIO_F32MSB, AUDIO_S16LSB, SDL_Convert_F32MSB_to_S16LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2284 { AUDIO_F32MSB, AUDIO_U16MSB, SDL_Convert_F32MSB_to_U16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2285 { AUDIO_F32MSB, AUDIO_S16MSB, SDL_Convert_F32MSB_to_S16MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2286 { AUDIO_F32MSB, AUDIO_S32LSB, SDL_Convert_F32MSB_to_S32LSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2287 { AUDIO_F32MSB, AUDIO_S32MSB, SDL_Convert_F32MSB_to_S32MSB },
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2288 { AUDIO_F32MSB, AUDIO_F32LSB, SDL_Convert_F32MSB_to_F32LSB },
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2289 #endif /* !NO_CONVERTERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2290 { 0, 0, NULL }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2291 };
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2292
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2293
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2294 #if !NO_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2295
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2296 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2297 SDL_Upsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2298 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2299 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2300 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2301 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2302
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2303 const int srcsize = cvt->len_cvt - 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2304 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2305 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2306 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2307 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2308 const Uint8 *target = ((const Uint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2309 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2310 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2311 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2312 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2313 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2314 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2315 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2316 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2317 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2318 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2319 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2320 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2321 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2322 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2323 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2324 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2325 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2326 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2327
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2328 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2329 SDL_Downsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2330 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2331 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2332 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2333 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2334
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2335 const int srcsize = cvt->len_cvt - 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2336 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2337 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2338 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2339 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2340 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2341 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2342 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2343 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2344 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2345 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2346 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2347 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2348 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2349 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2350 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2351 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2352 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2353 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2354 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2355 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2356 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2357 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2358 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2359
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2360 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2361 SDL_Upsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2362 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2363 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2364 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2365 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2366
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2367 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2368 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2369 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2370 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2371 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2372 const Uint8 *target = ((const Uint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2373 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2374 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2375 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2376 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2377 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2378 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2379 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2380 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2381 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2382 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2383 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2384 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2385 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2386 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2387 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2388 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2389 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2390 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2391 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2392 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2393 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2394 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2395 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2396
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2397 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2398 SDL_Downsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2399 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2400 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2401 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2402 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2403
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2404 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2405 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2406 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2407 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2408 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2409 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2410 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2411 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2412 Uint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2413 Uint8 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2414 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2415 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2416 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2417 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2418 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2419 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2420 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2421 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2422 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2423 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2424 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2425 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2426 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2427 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2428 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2429 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2430 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2431 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2432 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2433
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2434 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2435 SDL_Upsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2436 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2437 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2438 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2439 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2440
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2441 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2442 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2443 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2444 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2445 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2446 const Uint8 *target = ((const Uint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2447 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2448 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2449 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2450 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2451 Uint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2452 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2453 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2454 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2455 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2456 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2457 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2458 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2459 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2460 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2461 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2462 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2463 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2464 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2465 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2466 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2467 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2468 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2469 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2470 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2471 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2472 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2473 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2474 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2475 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2476 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2477 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2478 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2479 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2480
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2481 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2482 SDL_Downsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2483 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2484 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2485 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2486 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2487
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2488 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2489 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2490 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2491 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2492 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2493 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2494 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2495 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2496 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2497 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2498 Uint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2499 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2500 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2501 Uint8 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2502 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2503 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2504 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2505 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2506 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2507 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2508 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2509 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2510 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2511 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2512 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2513 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2514 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2515 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2516 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2517 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2518 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2519 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2520 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2521 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2522 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2523 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2524 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2525 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2526 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2527
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2528 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2529 SDL_Upsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2530 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2531 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2532 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2533 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2534
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2535 const int srcsize = cvt->len_cvt - 96;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2536 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2537 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2538 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2539 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2540 const Uint8 *target = ((const Uint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2541 Uint8 sample5 = src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2542 Uint8 sample4 = src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2543 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2544 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2545 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2546 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2547 Uint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2548 Uint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2549 Uint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2550 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2551 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2552 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2553 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2554 dst[5] = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2555 dst[4] = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2556 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2557 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2558 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2559 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2560 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2561 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2562 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2563 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2564 sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2565 sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2566 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2567 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2568 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2569 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2570 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2571 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2572 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2573 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2574 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2575 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2576 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2577 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2578 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2579 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2580 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2581 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2582 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2583 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2584
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2585 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2586 SDL_Downsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2587 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2588 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2589 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2590 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2591
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2592 const int srcsize = cvt->len_cvt - 96;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2593 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2594 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2595 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2596 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2597 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2598 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2599 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2600 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2601 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2602 Uint8 sample4 = src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2603 Uint8 sample5 = src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2604 Uint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2605 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2606 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2607 Uint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2608 Uint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2609 Uint8 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2610 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2611 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2612 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2613 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2614 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2615 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2616 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2617 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2618 dst[4] = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2619 dst[5] = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2620 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2621 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2622 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2623 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2624 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2625 sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2626 sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2627 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2628 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2629 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2630 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2631 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2632 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2633 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2634 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2635 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2636 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2637 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2638 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2639 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2640 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2641
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2642 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2643 SDL_Upsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2644 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2645 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2646 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2647 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2648
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2649 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2650 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2651 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2652 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2653 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2654 const Uint8 *target = ((const Uint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2655 Uint8 sample7 = src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2656 Uint8 sample6 = src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2657 Uint8 sample5 = src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2658 Uint8 sample4 = src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2659 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2660 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2661 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2662 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2663 Uint8 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2664 Uint8 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2665 Uint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2666 Uint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2667 Uint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2668 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2669 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2670 Uint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2671 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2672 dst[7] = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2673 dst[6] = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2674 dst[5] = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2675 dst[4] = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2676 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2677 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2678 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2679 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2680 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2681 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2682 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2683 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2684 sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2685 sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2686 sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2687 sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2688 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2689 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2690 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2691 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2692 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2693 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2694 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2695 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2696 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2697 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2698 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2699 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2700 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2701 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2702 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2703 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2704 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2705 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2706 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2707 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2708
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2709 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2710 SDL_Downsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2711 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2712 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2713 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U8, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2714 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2715
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2716 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2717 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2718 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2719 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2720 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2721 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2722 Uint8 sample0 = src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2723 Uint8 sample1 = src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2724 Uint8 sample2 = src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2725 Uint8 sample3 = src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2726 Uint8 sample4 = src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2727 Uint8 sample5 = src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2728 Uint8 sample6 = src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2729 Uint8 sample7 = src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2730 Uint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2731 Uint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2732 Uint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2733 Uint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2734 Uint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2735 Uint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2736 Uint8 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2737 Uint8 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2738 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2739 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2740 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2741 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2742 dst[0] = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2743 dst[1] = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2744 dst[2] = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2745 dst[3] = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2746 dst[4] = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2747 dst[5] = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2748 dst[6] = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2749 dst[7] = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2750 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2751 sample0 = (Uint8) ((((Sint16) src[0]) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2752 sample1 = (Uint8) ((((Sint16) src[1]) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2753 sample2 = (Uint8) ((((Sint16) src[2]) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2754 sample3 = (Uint8) ((((Sint16) src[3]) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2755 sample4 = (Uint8) ((((Sint16) src[4]) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2756 sample5 = (Uint8) ((((Sint16) src[5]) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2757 sample6 = (Uint8) ((((Sint16) src[6]) + ((Sint16) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2758 sample7 = (Uint8) ((((Sint16) src[7]) + ((Sint16) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2759 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2760 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2761 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2762 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2763 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2764 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2765 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2766 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2767 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2768 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2769 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2770 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2771 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2772 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2773 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2774 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2775
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2776 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2777 SDL_Upsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2778 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2779 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2780 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2781 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2782
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2783 const int srcsize = cvt->len_cvt - 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2784 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2785 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2786 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2787 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2788 const Sint8 *target = ((const Sint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2789 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2790 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2791 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2792 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2793 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2794 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2795 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2796 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2797 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2798 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2799 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2800 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2801 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2802 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2803 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2804 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2805 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2806 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2807
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2808 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2809 SDL_Downsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2810 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2811 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2812 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2813 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2814
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2815 const int srcsize = cvt->len_cvt - 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2816 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2817 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2818 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2819 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2820 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2821 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2822 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2823 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2824 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2825 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2826 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2827 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2828 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2829 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2830 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2831 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2832 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2833 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2834 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2835 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2836 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2837 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2838 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2839
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2840 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2841 SDL_Upsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2842 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2843 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2844 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2845 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2846
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2847 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2848 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2849 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2850 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2851 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2852 const Sint8 *target = ((const Sint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2853 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2854 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2855 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2856 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2857 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2858 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2859 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2860 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2861 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2862 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2863 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2864 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2865 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2866 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2867 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2868 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2869 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2870 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2871 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2872 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2873 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2874 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2875 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2876
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2877 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2878 SDL_Downsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2879 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2880 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2881 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2882 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2883
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2884 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2885 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2886 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2887 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2888 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2889 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2890 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2891 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2892 Sint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2893 Sint8 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2894 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2895 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2896 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2897 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2898 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2899 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2900 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2901 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2902 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2903 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2904 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2905 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2906 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2907 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2908 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2909 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2910 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2911 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2912 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2913
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2914 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2915 SDL_Upsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2916 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2917 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2918 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2919 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2920
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2921 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2922 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2923 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2924 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2925 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2926 const Sint8 *target = ((const Sint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2927 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2928 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2929 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2930 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2931 Sint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2932 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2933 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2934 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2935 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2936 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2937 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2938 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2939 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2940 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2941 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2942 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2943 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2944 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2945 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2946 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2947 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2948 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2949 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2950 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2951 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2952 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2953 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2954 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2955 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2956 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2957 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2958 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2959 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2960
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2961 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2962 SDL_Downsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2963 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
2964 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2965 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2966 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2967
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2968 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2969 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2970 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2971 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2972 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2973 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2974 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2975 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2976 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2977 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2978 Sint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2979 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2980 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2981 Sint8 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
2982 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2983 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2984 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2985 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2986 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2987 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2988 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2989 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2990 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2991 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2992 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2993 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2994 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2995 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2996 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2997 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2998 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
2999 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3000 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3001 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3002 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3003 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3004 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3005 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3006 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3007
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3008 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3009 SDL_Upsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3010 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3011 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3012 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3013 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3014
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3015 const int srcsize = cvt->len_cvt - 96;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3016 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3017 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3018 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3019 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3020 const Sint8 *target = ((const Sint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3021 Sint8 sample5 = ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3022 Sint8 sample4 = ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3023 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3024 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3025 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3026 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3027 Sint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3028 Sint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3029 Sint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3030 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3031 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3032 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3033 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3034 dst[5] = ((Sint8) sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3035 dst[4] = ((Sint8) sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3036 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3037 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3038 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3039 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3040 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3041 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3042 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3043 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3044 sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3045 sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3046 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3047 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3048 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3049 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3050 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3051 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3052 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3053 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3054 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3055 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3056 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3057 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3058 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3059 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3060 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3061 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3062 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3063 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3064
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3065 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3066 SDL_Downsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3067 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3068 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3069 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3070 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3071
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3072 const int srcsize = cvt->len_cvt - 96;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3073 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3074 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3075 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3076 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3077 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3078 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3079 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3080 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3081 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3082 Sint8 sample4 = ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3083 Sint8 sample5 = ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3084 Sint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3085 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3086 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3087 Sint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3088 Sint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3089 Sint8 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3090 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3091 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3092 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3093 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3094 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3095 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3096 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3097 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3098 dst[4] = ((Sint8) sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3099 dst[5] = ((Sint8) sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3100 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3101 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3102 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3103 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3104 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3105 sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3106 sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3107 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3108 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3109 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3110 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3111 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3112 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3113 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3114 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3115 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3116 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3117 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3118 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3119 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3120 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3121
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3122 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3123 SDL_Upsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3124 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3125 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3126 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3127 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3128
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3129 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3130 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3131 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3132 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3133 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3134 const Sint8 *target = ((const Sint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3135 Sint8 sample7 = ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3136 Sint8 sample6 = ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3137 Sint8 sample5 = ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3138 Sint8 sample4 = ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3139 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3140 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3141 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3142 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3143 Sint8 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3144 Sint8 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3145 Sint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3146 Sint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3147 Sint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3148 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3149 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3150 Sint8 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3151 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3152 dst[7] = ((Sint8) sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3153 dst[6] = ((Sint8) sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3154 dst[5] = ((Sint8) sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3155 dst[4] = ((Sint8) sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3156 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3157 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3158 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3159 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3160 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3161 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3162 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3163 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3164 sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3165 sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3166 sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3167 sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3168 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3169 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3170 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3171 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3172 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3173 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3174 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3175 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3176 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3177 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3178 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3179 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3180 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3181 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3182 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3183 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3184 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3185 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3186 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3187 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3188
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3189 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3190 SDL_Downsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3191 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3192 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3193 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S8, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3194 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3195
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3196 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3197 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3198 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3199 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3200 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3201 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3202 Sint8 sample0 = ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3203 Sint8 sample1 = ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3204 Sint8 sample2 = ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3205 Sint8 sample3 = ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3206 Sint8 sample4 = ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3207 Sint8 sample5 = ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3208 Sint8 sample6 = ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3209 Sint8 sample7 = ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3210 Sint8 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3211 Sint8 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3212 Sint8 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3213 Sint8 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3214 Sint8 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3215 Sint8 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3216 Sint8 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3217 Sint8 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3218 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3219 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3220 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3221 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3222 dst[0] = ((Sint8) sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3223 dst[1] = ((Sint8) sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3224 dst[2] = ((Sint8) sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3225 dst[3] = ((Sint8) sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3226 dst[4] = ((Sint8) sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3227 dst[5] = ((Sint8) sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3228 dst[6] = ((Sint8) sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3229 dst[7] = ((Sint8) sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3230 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3231 sample0 = (Sint8) ((((Sint16) ((Sint8) src[0])) + ((Sint16) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3232 sample1 = (Sint8) ((((Sint16) ((Sint8) src[1])) + ((Sint16) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3233 sample2 = (Sint8) ((((Sint16) ((Sint8) src[2])) + ((Sint16) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3234 sample3 = (Sint8) ((((Sint16) ((Sint8) src[3])) + ((Sint16) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3235 sample4 = (Sint8) ((((Sint16) ((Sint8) src[4])) + ((Sint16) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3236 sample5 = (Sint8) ((((Sint16) ((Sint8) src[5])) + ((Sint16) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3237 sample6 = (Sint8) ((((Sint16) ((Sint8) src[6])) + ((Sint16) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3238 sample7 = (Sint8) ((((Sint16) ((Sint8) src[7])) + ((Sint16) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3239 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3240 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3241 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3242 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3243 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3244 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3245 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3246 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3247 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3248 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3249 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3250 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3251 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3252 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3253 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3254 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3255
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3256 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3257 SDL_Upsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3258 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3259 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3260 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3261 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3262
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3263 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3264 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3265 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3266 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3267 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3268 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3269 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3270 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3271 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3272 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3273 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3274 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3275 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3276 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3277 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3278 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3279 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3280 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3281 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3282 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3283 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3284 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3285 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3286 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3287
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3288 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3289 SDL_Downsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3290 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3291 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3292 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3293 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3294
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3295 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3296 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3297 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3298 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3299 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3300 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3301 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3302 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3303 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3304 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3305 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3306 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3307 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3308 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3309 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3310 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3311 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3312 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3313 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3314 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3315 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3316 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3317 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3318 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3319
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3320 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3321 SDL_Upsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3322 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3323 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3324 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3325 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3326
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3327 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3328 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3329 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3330 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3331 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3332 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3333 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3334 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3335 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3336 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3337 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3338 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3339 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3340 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3341 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3342 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3343 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3344 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3345 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3346 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3347 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3348 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3349 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3350 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3351 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3352 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3353 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3354 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3355 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3356
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3357 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3358 SDL_Downsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3359 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3360 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3361 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3362 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3363
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3364 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3365 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3366 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3367 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3368 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3369 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3370 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3371 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3372 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3373 Uint16 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3374 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3375 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3376 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3377 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3378 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3379 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3380 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3381 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3382 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3383 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3384 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3385 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3386 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3387 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3388 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3389 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3390 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3391 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3392 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3393
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3394 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3395 SDL_Upsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3396 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3397 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3398 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3399 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3400
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3401 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3402 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3403 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3404 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3405 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3406 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3407 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3408 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3409 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3410 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3411 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3412 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3413 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3414 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3415 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3416 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3417 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3418 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3419 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3420 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3421 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3422 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3423 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3424 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3425 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3426 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3427 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3428 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3429 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3430 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3431 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3432 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3433 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3434 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3435 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3436 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3437 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3438 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3439 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3440
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3441 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3442 SDL_Downsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3443 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3444 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3445 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3446 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3447
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3448 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3449 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3450 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3451 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3452 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3453 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3454 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3455 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3456 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3457 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3458 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3459 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3460 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3461 Uint16 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3462 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3463 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3464 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3465 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3466 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3467 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3468 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3469 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3470 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3471 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3472 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3473 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3474 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3475 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3476 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3477 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3478 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3479 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3480 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3481 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3482 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3483 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3484 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3485 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3486 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3487
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3488 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3489 SDL_Upsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3490 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3491 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3492 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3493 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3494
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3495 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3496 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3497 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3498 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3499 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3500 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3501 Uint16 sample5 = SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3502 Uint16 sample4 = SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3503 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3504 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3505 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3506 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3507 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3508 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3509 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3510 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3511 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3512 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3513 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3514 dst[5] = SDL_SwapLE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3515 dst[4] = SDL_SwapLE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3516 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3517 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3518 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3519 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3520 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3521 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3522 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3523 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3524 sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3525 sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3526 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3527 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3528 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3529 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3530 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3531 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3532 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3533 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3534 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3535 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3536 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3537 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3538 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3539 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3540 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3541 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3542 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3543 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3544
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3545 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3546 SDL_Downsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3547 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3548 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3549 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3550 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3551
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3552 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3553 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3554 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3555 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3556 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3557 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3558 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3559 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3560 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3561 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3562 Uint16 sample4 = SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3563 Uint16 sample5 = SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3564 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3565 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3566 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3567 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3568 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3569 Uint16 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3570 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3571 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3572 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3573 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3574 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3575 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3576 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3577 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3578 dst[4] = SDL_SwapLE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3579 dst[5] = SDL_SwapLE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3580 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3581 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3582 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3583 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3584 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3585 sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3586 sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3587 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3588 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3589 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3590 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3591 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3592 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3593 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3594 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3595 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3596 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3597 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3598 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3599 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3600 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3601
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3602 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3603 SDL_Upsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3604 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3605 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3606 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3607 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3608
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3609 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3610 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3611 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3612 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3613 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3614 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3615 Uint16 sample7 = SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3616 Uint16 sample6 = SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3617 Uint16 sample5 = SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3618 Uint16 sample4 = SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3619 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3620 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3621 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3622 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3623 Uint16 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3624 Uint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3625 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3626 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3627 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3628 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3629 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3630 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3631 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3632 dst[7] = SDL_SwapLE16(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3633 dst[6] = SDL_SwapLE16(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3634 dst[5] = SDL_SwapLE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3635 dst[4] = SDL_SwapLE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3636 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3637 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3638 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3639 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3640 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3641 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3642 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3643 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3644 sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3645 sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3646 sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3647 sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3648 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3649 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3650 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3651 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3652 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3653 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3654 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3655 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3656 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3657 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3658 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3659 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3660 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3661 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3662 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3663 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3664 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3665 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3666 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3667 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3668
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3669 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3670 SDL_Downsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3671 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3672 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3673 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3674 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3675
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3676 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3677 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3678 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3679 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3680 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3681 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3682 Uint16 sample0 = SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3683 Uint16 sample1 = SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3684 Uint16 sample2 = SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3685 Uint16 sample3 = SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3686 Uint16 sample4 = SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3687 Uint16 sample5 = SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3688 Uint16 sample6 = SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3689 Uint16 sample7 = SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3690 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3691 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3692 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3693 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3694 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3695 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3696 Uint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3697 Uint16 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3698 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3699 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3700 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3701 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3702 dst[0] = SDL_SwapLE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3703 dst[1] = SDL_SwapLE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3704 dst[2] = SDL_SwapLE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3705 dst[3] = SDL_SwapLE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3706 dst[4] = SDL_SwapLE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3707 dst[5] = SDL_SwapLE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3708 dst[6] = SDL_SwapLE16(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3709 dst[7] = SDL_SwapLE16(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3710 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3711 sample0 = (Uint16) ((((Sint32) SDL_SwapLE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3712 sample1 = (Uint16) ((((Sint32) SDL_SwapLE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3713 sample2 = (Uint16) ((((Sint32) SDL_SwapLE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3714 sample3 = (Uint16) ((((Sint32) SDL_SwapLE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3715 sample4 = (Uint16) ((((Sint32) SDL_SwapLE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3716 sample5 = (Uint16) ((((Sint32) SDL_SwapLE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3717 sample6 = (Uint16) ((((Sint32) SDL_SwapLE16(src[6])) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3718 sample7 = (Uint16) ((((Sint32) SDL_SwapLE16(src[7])) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3719 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3720 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3721 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3722 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3723 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3724 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3725 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3726 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3727 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3728 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3729 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3730 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3731 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3732 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3733 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3734 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3735
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3736 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3737 SDL_Upsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3738 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3739 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3740 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3741 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3742
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3743 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3744 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3745 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3746 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3747 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3748 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3749 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3750 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3751 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3752 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3753 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3754 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3755 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3756 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3757 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3758 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3759 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3760 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3761 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3762 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3763 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3764 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3765 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3766 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3767
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3768 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3769 SDL_Downsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3770 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3771 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3772 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3773 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3774
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3775 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3776 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3777 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3778 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3779 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3780 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3781 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3782 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3783 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3784 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3785 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3786 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3787 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3788 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3789 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3790 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3791 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3792 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3793 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3794 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3795 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3796 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3797 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3798 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3799
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3800 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3801 SDL_Upsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3802 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3803 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3804 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3805 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3806
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3807 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3808 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3809 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3810 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3811 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3812 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3813 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3814 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3815 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3816 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3817 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3818 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3819 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3820 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3821 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3822 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3823 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3824 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3825 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3826 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3827 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3828 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3829 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3830 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3831 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3832 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3833 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3834 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3835 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3836
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3837 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3838 SDL_Downsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3839 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3840 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3841 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3842 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3843
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3844 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3845 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3846 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3847 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3848 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3849 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3850 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3851 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3852 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3853 Sint16 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3854 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3855 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3856 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3857 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3858 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3859 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3860 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3861 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3862 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3863 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3864 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3865 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3866 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3867 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3868 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3869 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3870 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3871 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3872 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3873
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3874 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3875 SDL_Upsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3876 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3877 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3878 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3879 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3880
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3881 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3882 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3883 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3884 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3885 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3886 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3887 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3888 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3889 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3890 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3891 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3892 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3893 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3894 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3895 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3896 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3897 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3898 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3899 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3900 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3901 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3902 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3903 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3904 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3905 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3906 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3907 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3908 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3909 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3910 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3911 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3912 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3913 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3914 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3915 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3916 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3917 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3918 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3919 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3920
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3921 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3922 SDL_Downsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3923 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3924 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3925 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3926 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3927
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3928 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3929 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3930 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3931 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3932 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3933 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3934 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3935 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3936 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3937 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3938 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3939 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3940 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3941 Sint16 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3942 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3943 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3944 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3945 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3946 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3947 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3948 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3949 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3950 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3951 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3952 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3953 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3954 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3955 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3956 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3957 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3958 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3959 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3960 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3961 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3962 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3963 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3964 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3965 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3966 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3967
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3968 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3969 SDL_Upsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3970 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
3971 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3972 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3973 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3974
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3975 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3976 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3977 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3978 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3979 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3980 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3981 Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3982 Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3983 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3984 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3985 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3986 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3987 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3988 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3989 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3990 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3991 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3992 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
3993 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3994 dst[5] = ((Sint16) SDL_SwapLE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3995 dst[4] = ((Sint16) SDL_SwapLE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3996 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3997 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3998 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
3999 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4000 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4001 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4002 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4003 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4004 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4005 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4006 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4007 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4008 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4009 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4010 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4011 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4012 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4013 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4014 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4015 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4016 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4017 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4018 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4019 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4020 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4021 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4022 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4023 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4024
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4025 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4026 SDL_Downsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4027 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4028 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4029 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4030 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4031
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4032 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4033 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4034 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4035 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4036 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4037 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4038 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4039 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4040 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4041 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4042 Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4043 Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4044 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4045 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4046 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4047 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4048 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4049 Sint16 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4050 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4051 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4052 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4053 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4054 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4055 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4056 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4057 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4058 dst[4] = ((Sint16) SDL_SwapLE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4059 dst[5] = ((Sint16) SDL_SwapLE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4060 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4061 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4062 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4063 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4064 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4065 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4066 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4067 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4068 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4069 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4070 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4071 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4072 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4073 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4074 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4075 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4076 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4077 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4078 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4079 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4080 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4081
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4082 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4083 SDL_Upsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4084 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4085 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4086 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4087 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4088
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4089 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4090 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4091 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4092 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4093 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4094 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4095 Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4096 Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4097 Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4098 Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4099 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4100 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4101 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4102 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4103 Sint16 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4104 Sint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4105 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4106 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4107 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4108 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4109 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4110 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4111 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4112 dst[7] = ((Sint16) SDL_SwapLE16(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4113 dst[6] = ((Sint16) SDL_SwapLE16(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4114 dst[5] = ((Sint16) SDL_SwapLE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4115 dst[4] = ((Sint16) SDL_SwapLE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4116 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4117 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4118 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4119 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4120 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4121 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4122 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4123 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4124 sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4125 sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4126 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4127 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4128 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4129 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4130 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4131 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4132 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4133 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4134 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4135 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4136 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4137 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4138 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4139 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4140 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4141 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4142 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4143 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4144 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4145 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4146 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4147 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4148
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4149 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4150 SDL_Downsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4151 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4152 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4153 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4154 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4155
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4156 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4157 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4158 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4159 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4160 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4161 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4162 Sint16 sample0 = ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4163 Sint16 sample1 = ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4164 Sint16 sample2 = ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4165 Sint16 sample3 = ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4166 Sint16 sample4 = ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4167 Sint16 sample5 = ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4168 Sint16 sample6 = ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4169 Sint16 sample7 = ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4170 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4171 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4172 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4173 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4174 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4175 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4176 Sint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4177 Sint16 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4178 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4179 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4180 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4181 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4182 dst[0] = ((Sint16) SDL_SwapLE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4183 dst[1] = ((Sint16) SDL_SwapLE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4184 dst[2] = ((Sint16) SDL_SwapLE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4185 dst[3] = ((Sint16) SDL_SwapLE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4186 dst[4] = ((Sint16) SDL_SwapLE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4187 dst[5] = ((Sint16) SDL_SwapLE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4188 dst[6] = ((Sint16) SDL_SwapLE16(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4189 dst[7] = ((Sint16) SDL_SwapLE16(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4190 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4191 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4192 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4193 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4194 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4195 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4196 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4197 sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4198 sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapLE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4199 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4200 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4201 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4202 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4203 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4204 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4205 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4206 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4207 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4208 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4209 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4210 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4211 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4212 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4213 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4214 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4215
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4216 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4217 SDL_Upsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4218 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4219 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4220 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4221 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4222
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4223 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4224 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4225 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4226 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4227 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4228 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4229 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4230 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4231 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4232 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4233 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4234 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4235 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4236 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4237 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4238 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4239 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4240 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4241 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4242 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4243 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4244 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4245 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4246 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4247
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4248 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4249 SDL_Downsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4250 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4251 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4252 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4253 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4254
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4255 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4256 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4257 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4258 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4259 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4260 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4261 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4262 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4263 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4264 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4265 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4266 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4267 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4268 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4269 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4270 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4271 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4272 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4273 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4274 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4275 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4276 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4277 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4278 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4279
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4280 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4281 SDL_Upsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4282 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4283 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4284 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4285 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4286
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4287 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4288 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4289 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4290 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4291 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4292 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4293 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4294 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4295 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4296 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4297 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4298 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4299 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4300 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4301 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4302 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4303 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4304 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4305 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4306 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4307 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4308 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4309 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4310 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4311 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4312 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4313 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4314 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4315 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4316
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4317 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4318 SDL_Downsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4319 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4320 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4321 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4322 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4323
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4324 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4325 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4326 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4327 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4328 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4329 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4330 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4331 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4332 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4333 Uint16 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4334 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4335 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4336 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4337 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4338 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4339 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4340 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4341 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4342 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4343 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4344 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4345 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4346 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4347 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4348 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4349 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4350 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4351 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4352 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4353
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4354 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4355 SDL_Upsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4356 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4357 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4358 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4359 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4360
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4361 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4362 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4363 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4364 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4365 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4366 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4367 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4368 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4369 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4370 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4371 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4372 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4373 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4374 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4375 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4376 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4377 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4378 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4379 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4380 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4381 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4382 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4383 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4384 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4385 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4386 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4387 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4388 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4389 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4390 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4391 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4392 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4393 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4394 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4395 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4396 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4397 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4398 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4399 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4400
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4401 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4402 SDL_Downsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4403 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4404 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4405 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4406 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4407
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4408 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4409 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4410 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4411 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4412 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4413 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4414 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4415 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4416 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4417 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4418 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4419 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4420 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4421 Uint16 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4422 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4423 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4424 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4425 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4426 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4427 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4428 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4429 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4430 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4431 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4432 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4433 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4434 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4435 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4436 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4437 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4438 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4439 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4440 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4441 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4442 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4443 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4444 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4445 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4446 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4447
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4448 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4449 SDL_Upsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4450 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4451 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4452 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4453 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4454
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4455 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4456 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4457 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4458 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4459 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4460 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4461 Uint16 sample5 = SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4462 Uint16 sample4 = SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4463 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4464 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4465 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4466 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4467 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4468 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4469 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4470 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4471 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4472 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4473 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4474 dst[5] = SDL_SwapBE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4475 dst[4] = SDL_SwapBE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4476 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4477 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4478 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4479 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4480 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4481 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4482 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4483 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4484 sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4485 sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4486 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4487 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4488 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4489 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4490 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4491 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4492 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4493 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4494 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4495 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4496 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4497 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4498 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4499 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4500 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4501 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4502 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4503 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4504
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4505 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4506 SDL_Downsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4507 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4508 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4509 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4510 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4511
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4512 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4513 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4514 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4515 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4516 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4517 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4518 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4519 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4520 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4521 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4522 Uint16 sample4 = SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4523 Uint16 sample5 = SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4524 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4525 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4526 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4527 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4528 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4529 Uint16 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4530 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4531 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4532 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4533 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4534 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4535 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4536 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4537 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4538 dst[4] = SDL_SwapBE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4539 dst[5] = SDL_SwapBE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4540 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4541 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4542 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4543 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4544 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4545 sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4546 sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4547 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4548 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4549 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4550 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4551 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4552 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4553 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4554 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4555 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4556 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4557 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4558 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4559 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4560 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4561
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4562 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4563 SDL_Upsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4564 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4565 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4566 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4567 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4568
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4569 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4570 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4571 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4572 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4573 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4574 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4575 Uint16 sample7 = SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4576 Uint16 sample6 = SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4577 Uint16 sample5 = SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4578 Uint16 sample4 = SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4579 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4580 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4581 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4582 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4583 Uint16 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4584 Uint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4585 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4586 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4587 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4588 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4589 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4590 Uint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4591 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4592 dst[7] = SDL_SwapBE16(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4593 dst[6] = SDL_SwapBE16(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4594 dst[5] = SDL_SwapBE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4595 dst[4] = SDL_SwapBE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4596 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4597 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4598 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4599 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4600 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4601 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4602 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4603 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4604 sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4605 sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4606 sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4607 sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4608 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4609 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4610 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4611 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4612 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4613 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4614 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4615 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4616 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4617 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4618 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4619 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4620 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4621 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4622 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4623 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4624 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4625 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4626 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4627 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4628
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4629 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4630 SDL_Downsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4631 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4632 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4633 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_U16MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4634 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4635
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4636 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4637 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4638 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4639 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4640 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4641 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4642 Uint16 sample0 = SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4643 Uint16 sample1 = SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4644 Uint16 sample2 = SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4645 Uint16 sample3 = SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4646 Uint16 sample4 = SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4647 Uint16 sample5 = SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4648 Uint16 sample6 = SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4649 Uint16 sample7 = SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4650 Uint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4651 Uint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4652 Uint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4653 Uint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4654 Uint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4655 Uint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4656 Uint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4657 Uint16 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4658 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4659 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4660 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4661 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4662 dst[0] = SDL_SwapBE16(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4663 dst[1] = SDL_SwapBE16(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4664 dst[2] = SDL_SwapBE16(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4665 dst[3] = SDL_SwapBE16(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4666 dst[4] = SDL_SwapBE16(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4667 dst[5] = SDL_SwapBE16(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4668 dst[6] = SDL_SwapBE16(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4669 dst[7] = SDL_SwapBE16(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4670 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4671 sample0 = (Uint16) ((((Sint32) SDL_SwapBE16(src[0])) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4672 sample1 = (Uint16) ((((Sint32) SDL_SwapBE16(src[1])) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4673 sample2 = (Uint16) ((((Sint32) SDL_SwapBE16(src[2])) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4674 sample3 = (Uint16) ((((Sint32) SDL_SwapBE16(src[3])) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4675 sample4 = (Uint16) ((((Sint32) SDL_SwapBE16(src[4])) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4676 sample5 = (Uint16) ((((Sint32) SDL_SwapBE16(src[5])) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4677 sample6 = (Uint16) ((((Sint32) SDL_SwapBE16(src[6])) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4678 sample7 = (Uint16) ((((Sint32) SDL_SwapBE16(src[7])) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4679 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4680 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4681 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4682 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4683 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4684 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4685 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4686 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4687 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4688 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4689 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4690 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4691 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4692 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4693 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4694 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4695
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4696 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4697 SDL_Upsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4698 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4699 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4700 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4701 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4702
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4703 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4704 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4705 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4706 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4707 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4708 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4709 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4710 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4711 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4712 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4713 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4714 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4715 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4716 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4717 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4718 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4719 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4720 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4721 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4722 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4723 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4724 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4725 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4726 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4727
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4728 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4729 SDL_Downsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4730 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4731 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4732 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4733 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4734
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4735 const int srcsize = cvt->len_cvt - 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4736 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4737 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4738 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4739 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4740 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4741 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4742 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4743 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4744 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4745 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4746 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4747 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4748 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4749 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4750 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4751 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4752 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4753 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4754 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4755 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4756 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4757 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4758 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4759
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4760 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4761 SDL_Upsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4762 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4763 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4764 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4765 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4766
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4767 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4768 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4769 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4770 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4771 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4772 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4773 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4774 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4775 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4776 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4777 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4778 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4779 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4780 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4781 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4782 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4783 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4784 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4785 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4786 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4787 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4788 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4789 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4790 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4791 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4792 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4793 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4794 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4795 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4796
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4797 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4798 SDL_Downsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4799 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4800 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4801 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4802 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4803
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4804 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4805 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4806 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4807 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4808 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4809 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4810 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4811 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4812 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4813 Sint16 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4814 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4815 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4816 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4817 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4818 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4819 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4820 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4821 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4822 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4823 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4824 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4825 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4826 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4827 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4828 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4829 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4830 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4831 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4832 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4833
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4834 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4835 SDL_Upsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4836 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4837 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4838 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4839 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4840
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4841 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4842 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4843 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4844 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4845 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4846 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4847 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4848 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4849 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4850 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4851 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4852 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4853 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4854 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4855 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4856 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4857 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4858 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4859 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4860 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4861 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4862 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4863 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4864 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4865 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4866 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4867 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4868 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4869 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4870 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4871 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4872 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4873 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4874 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4875 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4876 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4877 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4878 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4879 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4880
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4881 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4882 SDL_Downsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4883 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4884 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4885 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4886 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4887
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4888 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4889 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4890 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4891 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4892 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4893 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4894 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4895 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4896 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4897 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4898 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4899 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4900 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4901 Sint16 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4902 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4903 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4904 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4905 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4906 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4907 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4908 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4909 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4910 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4911 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4912 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4913 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4914 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4915 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4916 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4917 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4918 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4919 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4920 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4921 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4922 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4923 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4924 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4925 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4926 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4927
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4928 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4929 SDL_Upsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4930 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4931 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4932 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4933 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4934
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4935 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4936 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4937 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4938 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4939 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4940 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4941 Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4942 Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4943 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4944 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4945 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4946 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4947 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4948 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4949 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4950 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4951 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4952 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
4953 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4954 dst[5] = ((Sint16) SDL_SwapBE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4955 dst[4] = ((Sint16) SDL_SwapBE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4956 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4957 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4958 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4959 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4960 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4961 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4962 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4963 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4964 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4965 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4966 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4967 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4968 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4969 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4970 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4971 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4972 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4973 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4974 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4975 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4976 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4977 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4978 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4979 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4980 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4981 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4982 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4983 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4984
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4985 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4986 SDL_Downsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4987 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
4988 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4989 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4990 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4991
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4992 const int srcsize = cvt->len_cvt - 192;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4993 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4994 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4995 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4996 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4997 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4998 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
4999 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5000 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5001 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5002 Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5003 Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5004 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5005 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5006 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5007 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5008 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5009 Sint16 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5010 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5011 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5012 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5013 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5014 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5015 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5016 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5017 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5018 dst[4] = ((Sint16) SDL_SwapBE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5019 dst[5] = ((Sint16) SDL_SwapBE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5020 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5021 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5022 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5023 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5024 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5025 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5026 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5027 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5028 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5029 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5030 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5031 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5032 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5033 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5034 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5035 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5036 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5037 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5038 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5039 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5040 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5041
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5042 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5043 SDL_Upsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5044 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5045 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5046 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5047 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5048
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5049 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5050 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5051 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5052 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5053 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5054 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5055 Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5056 Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5057 Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5058 Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5059 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5060 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5061 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5062 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5063 Sint16 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5064 Sint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5065 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5066 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5067 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5068 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5069 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5070 Sint16 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5071 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5072 dst[7] = ((Sint16) SDL_SwapBE16(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5073 dst[6] = ((Sint16) SDL_SwapBE16(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5074 dst[5] = ((Sint16) SDL_SwapBE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5075 dst[4] = ((Sint16) SDL_SwapBE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5076 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5077 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5078 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5079 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5080 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5081 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5082 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5083 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5084 sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5085 sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5086 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5087 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5088 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5089 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5090 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5091 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5092 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5093 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5094 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5095 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5096 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5097 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5098 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5099 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5100 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5101 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5102 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5103 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5104 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5105 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5106 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5107 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5108
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5109 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5110 SDL_Downsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5111 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5112 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5113 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S16MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5114 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5115
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5116 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5117 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5118 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5119 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5120 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5121 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5122 Sint16 sample0 = ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5123 Sint16 sample1 = ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5124 Sint16 sample2 = ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5125 Sint16 sample3 = ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5126 Sint16 sample4 = ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5127 Sint16 sample5 = ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5128 Sint16 sample6 = ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5129 Sint16 sample7 = ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5130 Sint16 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5131 Sint16 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5132 Sint16 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5133 Sint16 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5134 Sint16 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5135 Sint16 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5136 Sint16 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5137 Sint16 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5138 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5139 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5140 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5141 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5142 dst[0] = ((Sint16) SDL_SwapBE16(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5143 dst[1] = ((Sint16) SDL_SwapBE16(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5144 dst[2] = ((Sint16) SDL_SwapBE16(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5145 dst[3] = ((Sint16) SDL_SwapBE16(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5146 dst[4] = ((Sint16) SDL_SwapBE16(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5147 dst[5] = ((Sint16) SDL_SwapBE16(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5148 dst[6] = ((Sint16) SDL_SwapBE16(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5149 dst[7] = ((Sint16) SDL_SwapBE16(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5150 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5151 sample0 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[0]))) + ((Sint32) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5152 sample1 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[1]))) + ((Sint32) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5153 sample2 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[2]))) + ((Sint32) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5154 sample3 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[3]))) + ((Sint32) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5155 sample4 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[4]))) + ((Sint32) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5156 sample5 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[5]))) + ((Sint32) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5157 sample6 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[6]))) + ((Sint32) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5158 sample7 = (Sint16) ((((Sint32) ((Sint16) SDL_SwapBE16(src[7]))) + ((Sint32) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5159 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5160 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5161 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5162 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5163 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5164 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5165 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5166 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5167 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5168 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5169 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5170 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5171 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5172 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5173 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5174 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5175
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5176 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5177 SDL_Upsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5178 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5179 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5180 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5181 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5182
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5183 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5184 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5185 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5186 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5187 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5188 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5189 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5190 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5191 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5192 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5193 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5194 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5195 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5196 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5197 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5198 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5199 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5200 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5201 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5202 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5203 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5204 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5205 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5206 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5207
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5208 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5209 SDL_Downsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5210 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5211 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5212 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5213 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5214
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5215 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5216 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5217 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5218 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5219 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5220 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5221 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5222 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5223 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5224 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5225 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5226 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5227 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5228 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5229 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5230 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5231 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5232 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5233 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5234 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5235 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5236 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5237 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5238 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5239
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5240 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5241 SDL_Upsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5242 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5243 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5244 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5245 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5246
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5247 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5248 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5249 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5250 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5251 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5252 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5253 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5254 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5255 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5256 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5257 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5258 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5259 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5260 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5261 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5262 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5263 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5264 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5265 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5266 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5267 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5268 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5269 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5270 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5271 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5272 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5273 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5274 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5275 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5276
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5277 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5278 SDL_Downsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5279 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5280 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5281 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5282 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5283
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5284 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5285 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5286 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5287 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5288 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5289 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5290 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5291 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5292 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5293 Sint32 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5294 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5295 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5296 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5297 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5298 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5299 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5300 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5301 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5302 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5303 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5304 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5305 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5306 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5307 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5308 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5309 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5310 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5311 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5312 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5313
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5314 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5315 SDL_Upsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5316 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5317 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5318 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5319 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5320
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5321 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5322 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5323 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5324 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5325 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5326 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5327 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5328 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5329 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5330 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5331 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5332 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5333 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5334 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5335 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5336 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5337 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5338 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5339 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5340 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5341 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5342 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5343 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5344 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5345 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5346 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5347 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5348 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5349 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5350 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5351 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5352 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5353 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5354 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5355 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5356 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5357 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5358 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5359 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5360
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5361 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5362 SDL_Downsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5363 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5364 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5365 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5366 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5367
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5368 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5369 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5370 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5371 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5372 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5373 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5374 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5375 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5376 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5377 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5378 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5379 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5380 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5381 Sint32 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5382 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5383 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5384 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5385 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5386 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5387 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5388 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5389 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5390 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5391 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5392 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5393 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5394 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5395 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5396 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5397 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5398 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5399 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5400 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5401 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5402 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5403 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5404 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5405 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5406 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5407
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5408 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5409 SDL_Upsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5410 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5411 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5412 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5413 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5414
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5415 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5416 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5417 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5418 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5419 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5420 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5421 Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5422 Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5423 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5424 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5425 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5426 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5427 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5428 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5429 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5430 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5431 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5432 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5433 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5434 dst[5] = ((Sint32) SDL_SwapLE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5435 dst[4] = ((Sint32) SDL_SwapLE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5436 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5437 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5438 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5439 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5440 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5441 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5442 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5443 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5444 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5445 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5446 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5447 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5448 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5449 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5450 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5451 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5452 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5453 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5454 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5455 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5456 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5457 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5458 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5459 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5460 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5461 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5462 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5463 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5464
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5465 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5466 SDL_Downsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5467 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5468 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5469 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5470 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5471
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5472 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5473 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5474 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5475 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5476 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5477 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5478 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5479 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5480 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5481 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5482 Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5483 Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5484 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5485 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5486 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5487 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5488 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5489 Sint32 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5490 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5491 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5492 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5493 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5494 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5495 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5496 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5497 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5498 dst[4] = ((Sint32) SDL_SwapLE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5499 dst[5] = ((Sint32) SDL_SwapLE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5500 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5501 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5502 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5503 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5504 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5505 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5506 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5507 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5508 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5509 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5510 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5511 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5512 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5513 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5514 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5515 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5516 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5517 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5518 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5519 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5520 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5521
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5522 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5523 SDL_Upsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5524 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5525 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5526 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5527 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5528
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5529 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5530 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5531 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5532 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5533 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5534 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5535 Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5536 Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5537 Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5538 Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5539 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5540 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5541 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5542 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5543 Sint32 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5544 Sint32 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5545 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5546 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5547 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5548 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5549 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5550 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5551 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5552 dst[7] = ((Sint32) SDL_SwapLE32(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5553 dst[6] = ((Sint32) SDL_SwapLE32(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5554 dst[5] = ((Sint32) SDL_SwapLE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5555 dst[4] = ((Sint32) SDL_SwapLE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5556 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5557 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5558 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5559 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5560 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5561 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5562 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5563 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5564 sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5565 sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5566 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5567 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5568 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5569 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5570 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5571 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5572 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5573 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5574 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5575 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5576 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5577 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5578 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5579 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5580 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5581 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5582 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5583 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5584 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5585 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5586 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5587 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5588
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5589 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5590 SDL_Downsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5591 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5592 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5593 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5594 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5595
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5596 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5597 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5598 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5599 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5600 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5601 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5602 Sint32 sample0 = ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5603 Sint32 sample1 = ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5604 Sint32 sample2 = ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5605 Sint32 sample3 = ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5606 Sint32 sample4 = ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5607 Sint32 sample5 = ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5608 Sint32 sample6 = ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5609 Sint32 sample7 = ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5610 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5611 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5612 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5613 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5614 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5615 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5616 Sint32 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5617 Sint32 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5618 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5619 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5620 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5621 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5622 dst[0] = ((Sint32) SDL_SwapLE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5623 dst[1] = ((Sint32) SDL_SwapLE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5624 dst[2] = ((Sint32) SDL_SwapLE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5625 dst[3] = ((Sint32) SDL_SwapLE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5626 dst[4] = ((Sint32) SDL_SwapLE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5627 dst[5] = ((Sint32) SDL_SwapLE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5628 dst[6] = ((Sint32) SDL_SwapLE32(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5629 dst[7] = ((Sint32) SDL_SwapLE32(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5630 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5631 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5632 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5633 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5634 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5635 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5636 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5637 sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5638 sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapLE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5639 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5640 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5641 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5642 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5643 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5644 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5645 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5646 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5647 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5648 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5649 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5650 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5651 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5652 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5653 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5654 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5655
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5656 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5657 SDL_Upsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5658 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5659 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5660 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5661 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5662
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5663 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5664 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5665 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5666 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5667 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5668 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5669 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5670 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5671 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5672 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5673 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5674 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5675 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5676 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5677 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5678 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5679 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5680 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5681 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5682 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5683 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5684 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5685 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5686 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5687
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5688 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5689 SDL_Downsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5690 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5691 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5692 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5693 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5694
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5695 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5696 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5697 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5698 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5699 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5700 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5701 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5702 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5703 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5704 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5705 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5706 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5707 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5708 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5709 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5710 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5711 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5712 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5713 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5714 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5715 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5716 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5717 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5718 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5719
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5720 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5721 SDL_Upsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5722 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5723 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5724 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5725 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5726
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5727 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5728 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5729 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5730 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5731 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5732 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5733 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5734 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5735 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5736 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5737 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5738 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5739 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5740 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5741 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5742 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5743 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5744 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5745 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5746 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5747 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5748 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5749 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5750 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5751 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5752 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5753 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5754 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5755 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5756
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5757 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5758 SDL_Downsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5759 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5760 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5761 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5762 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5763
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5764 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5765 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5766 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5767 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5768 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5769 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5770 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5771 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5772 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5773 Sint32 last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5774 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5775 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5776 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5777 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5778 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5779 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5780 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5781 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5782 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5783 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5784 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5785 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5786 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5787 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5788 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5789 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5790 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5791 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5792 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5793
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5794 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5795 SDL_Upsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5796 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5797 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5798 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5799 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5800
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5801 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5802 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5803 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5804 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5805 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5806 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5807 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5808 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5809 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5810 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5811 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5812 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5813 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5814 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5815 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5816 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5817 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5818 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5819 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5820 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5821 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5822 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5823 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5824 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5825 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5826 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5827 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5828 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5829 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5830 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5831 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5832 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5833 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5834 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5835 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5836 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5837 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5838 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5839 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5840
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5841 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5842 SDL_Downsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5843 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5844 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5845 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5846 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5847
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5848 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5849 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5850 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5851 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5852 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5853 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5854 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5855 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5856 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5857 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5858 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5859 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5860 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5861 Sint32 last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5862 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5863 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5864 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5865 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5866 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5867 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5868 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5869 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5870 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5871 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5872 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5873 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5874 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5875 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5876 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5877 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5878 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5879 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5880 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5881 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5882 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5883 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5884 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5885 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5886 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5887
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5888 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5889 SDL_Upsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5890 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5891 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5892 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5893 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5894
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5895 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5896 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5897 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5898 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5899 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5900 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5901 Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5902 Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5903 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5904 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5905 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5906 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5907 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5908 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5909 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5910 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5911 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5912 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5913 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5914 dst[5] = ((Sint32) SDL_SwapBE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5915 dst[4] = ((Sint32) SDL_SwapBE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5916 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5917 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5918 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5919 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5920 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5921 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5922 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5923 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5924 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5925 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5926 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5927 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5928 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5929 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5930 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5931 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5932 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5933 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5934 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5935 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5936 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5937 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5938 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5939 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5940 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5941 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5942 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5943 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5944
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5945 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5946 SDL_Downsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5947 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
5948 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5949 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5950 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5951
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5952 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5953 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5954 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5955 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5956 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5957 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5958 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5959 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5960 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5961 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5962 Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5963 Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5964 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5965 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5966 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5967 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5968 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5969 Sint32 last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
5970 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5971 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5972 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5973 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5974 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5975 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5976 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5977 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5978 dst[4] = ((Sint32) SDL_SwapBE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5979 dst[5] = ((Sint32) SDL_SwapBE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5980 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5981 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5982 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5983 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5984 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5985 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5986 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5987 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5988 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5989 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5990 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5991 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5992 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5993 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5994 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5995 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5996 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5997 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5998 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
5999 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6000 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6001
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6002 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6003 SDL_Upsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6004 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6005 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6006 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6007 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6008
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6009 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6010 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6011 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6012 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6013 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6014 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6015 Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6016 Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6017 Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6018 Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6019 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6020 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6021 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6022 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6023 Sint32 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6024 Sint32 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6025 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6026 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6027 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6028 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6029 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6030 Sint32 last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6031 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6032 dst[7] = ((Sint32) SDL_SwapBE32(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6033 dst[6] = ((Sint32) SDL_SwapBE32(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6034 dst[5] = ((Sint32) SDL_SwapBE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6035 dst[4] = ((Sint32) SDL_SwapBE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6036 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6037 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6038 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6039 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6040 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6041 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6042 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6043 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6044 sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6045 sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6046 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6047 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6048 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6049 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6050 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6051 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6052 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6053 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6054 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6055 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6056 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6057 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6058 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6059 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6060 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6061 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6062 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6063 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6064 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6065 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6066 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6067 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6068
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6069 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6070 SDL_Downsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6071 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6072 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6073 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_S32MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6074 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6075
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6076 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6077 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6078 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6079 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6080 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6081 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6082 Sint32 sample0 = ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6083 Sint32 sample1 = ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6084 Sint32 sample2 = ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6085 Sint32 sample3 = ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6086 Sint32 sample4 = ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6087 Sint32 sample5 = ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6088 Sint32 sample6 = ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6089 Sint32 sample7 = ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6090 Sint32 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6091 Sint32 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6092 Sint32 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6093 Sint32 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6094 Sint32 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6095 Sint32 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6096 Sint32 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6097 Sint32 last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6098 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6099 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6100 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6101 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6102 dst[0] = ((Sint32) SDL_SwapBE32(sample0));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6103 dst[1] = ((Sint32) SDL_SwapBE32(sample1));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6104 dst[2] = ((Sint32) SDL_SwapBE32(sample2));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6105 dst[3] = ((Sint32) SDL_SwapBE32(sample3));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6106 dst[4] = ((Sint32) SDL_SwapBE32(sample4));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6107 dst[5] = ((Sint32) SDL_SwapBE32(sample5));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6108 dst[6] = ((Sint32) SDL_SwapBE32(sample6));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6109 dst[7] = ((Sint32) SDL_SwapBE32(sample7));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6110 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6111 sample0 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[0]))) + ((Sint64) last_sample0)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6112 sample1 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[1]))) + ((Sint64) last_sample1)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6113 sample2 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[2]))) + ((Sint64) last_sample2)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6114 sample3 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[3]))) + ((Sint64) last_sample3)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6115 sample4 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[4]))) + ((Sint64) last_sample4)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6116 sample5 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[5]))) + ((Sint64) last_sample5)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6117 sample6 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[6]))) + ((Sint64) last_sample6)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6118 sample7 = (Sint32) ((((Sint64) ((Sint32) SDL_SwapBE32(src[7]))) + ((Sint64) last_sample7)) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6119 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6120 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6121 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6122 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6123 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6124 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6125 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6126 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6127 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6128 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6129 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6130 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6131 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6132 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6133 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6134 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6135
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6136 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6137 SDL_Upsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6138 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6139 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6140 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6141 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6142
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6143 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6144 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6145 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6146 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6147 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6148 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6149 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6150 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6151 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6152 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6153 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6154 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6155 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6156 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6157 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6158 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6159 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6160 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6161 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6162 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6163 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6164 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6165 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6166 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6167
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6168 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6169 SDL_Downsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6170 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6171 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6172 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6173 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6174
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6175 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6176 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6177 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6178 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6179 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6180 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6181 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6182 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6183 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6184 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6185 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6186 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6187 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6188 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6189 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6190 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6191 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6192 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6193 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6194 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6195 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6196 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6197 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6198 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6199
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6200 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6201 SDL_Upsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6202 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6203 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6204 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6205 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6206
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6207 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6208 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6209 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6210 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6211 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6212 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6213 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6214 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6215 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6216 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6217 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6218 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6219 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6220 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6221 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6222 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6223 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6224 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6225 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6226 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6227 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6228 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6229 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6230 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6231 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6232 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6233 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6234 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6235 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6236
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6237 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6238 SDL_Downsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6239 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6240 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6241 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6242 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6243
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6244 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6245 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6246 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6247 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6248 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6249 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6250 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6251 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6252 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6253 float last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6254 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6255 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6256 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6257 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6258 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6259 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6260 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6261 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6262 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6263 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6264 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6265 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6266 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6267 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6268 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6269 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6270 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6271 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6272 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6273
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6274 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6275 SDL_Upsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6276 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6277 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6278 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6279 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6280
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6281 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6282 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6283 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6284 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6285 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6286 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6287 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6288 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6289 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6290 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6291 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6292 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6293 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6294 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6295 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6296 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6297 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6298 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6299 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6300 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6301 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6302 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6303 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6304 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6305 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6306 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6307 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6308 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6309 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6310 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6311 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6312 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6313 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6314 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6315 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6316 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6317 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6318 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6319 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6320
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6321 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6322 SDL_Downsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6323 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6324 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6325 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6326 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6327
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6328 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6329 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6330 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6331 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6332 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6333 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6334 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6335 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6336 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6337 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6338 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6339 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6340 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6341 float last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6342 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6343 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6344 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6345 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6346 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6347 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6348 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6349 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6350 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6351 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6352 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6353 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6354 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6355 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6356 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6357 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6358 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6359 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6360 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6361 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6362 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6363 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6364 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6365 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6366 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6367
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6368 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6369 SDL_Upsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6370 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6371 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6372 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6373 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6374
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6375 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6376 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6377 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6378 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6379 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6380 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6381 float sample5 = SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6382 float sample4 = SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6383 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6384 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6385 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6386 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6387 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6388 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6389 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6390 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6391 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6392 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6393 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6394 dst[5] = SDL_SwapFloatLE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6395 dst[4] = SDL_SwapFloatLE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6396 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6397 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6398 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6399 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6400 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6401 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6402 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6403 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6404 sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6405 sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6406 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6407 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6408 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6409 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6410 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6411 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6412 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6413 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6414 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6415 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6416 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6417 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6418 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6419 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6420 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6421 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6422 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6423 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6424
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6425 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6426 SDL_Downsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6427 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6428 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6429 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6430 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6431
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6432 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6433 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6434 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6435 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6436 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6437 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6438 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6439 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6440 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6441 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6442 float sample4 = SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6443 float sample5 = SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6444 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6445 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6446 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6447 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6448 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6449 float last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6450 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6451 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6452 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6453 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6454 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6455 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6456 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6457 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6458 dst[4] = SDL_SwapFloatLE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6459 dst[5] = SDL_SwapFloatLE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6460 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6461 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6462 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6463 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6464 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6465 sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6466 sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6467 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6468 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6469 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6470 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6471 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6472 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6473 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6474 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6475 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6476 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6477 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6478 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6479 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6480 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6481
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6482 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6483 SDL_Upsample_F32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6484 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6485 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6486 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6487 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6488
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6489 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6490 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6491 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6492 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6493 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6494 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6495 float sample7 = SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6496 float sample6 = SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6497 float sample5 = SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6498 float sample4 = SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6499 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6500 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6501 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6502 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6503 float last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6504 float last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6505 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6506 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6507 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6508 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6509 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6510 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6511 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6512 dst[7] = SDL_SwapFloatLE(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6513 dst[6] = SDL_SwapFloatLE(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6514 dst[5] = SDL_SwapFloatLE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6515 dst[4] = SDL_SwapFloatLE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6516 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6517 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6518 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6519 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6520 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6521 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6522 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6523 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6524 sample7 = (float) ((((double) SDL_SwapFloatLE(src[7])) + ((double) last_sample7)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6525 sample6 = (float) ((((double) SDL_SwapFloatLE(src[6])) + ((double) last_sample6)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6526 sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6527 sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6528 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6529 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6530 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6531 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6532 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6533 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6534 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6535 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6536 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6537 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6538 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6539 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6540 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6541 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6542 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6543 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6544 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6545 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6546 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6547 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6548
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6549 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6550 SDL_Downsample_F32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6551 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6552 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6553 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32LSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6554 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6555
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6556 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6557 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6558 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6559 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6560 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6561 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6562 float sample0 = SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6563 float sample1 = SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6564 float sample2 = SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6565 float sample3 = SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6566 float sample4 = SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6567 float sample5 = SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6568 float sample6 = SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6569 float sample7 = SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6570 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6571 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6572 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6573 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6574 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6575 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6576 float last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6577 float last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6578 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6579 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6580 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6581 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6582 dst[0] = SDL_SwapFloatLE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6583 dst[1] = SDL_SwapFloatLE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6584 dst[2] = SDL_SwapFloatLE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6585 dst[3] = SDL_SwapFloatLE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6586 dst[4] = SDL_SwapFloatLE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6587 dst[5] = SDL_SwapFloatLE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6588 dst[6] = SDL_SwapFloatLE(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6589 dst[7] = SDL_SwapFloatLE(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6590 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6591 sample0 = (float) ((((double) SDL_SwapFloatLE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6592 sample1 = (float) ((((double) SDL_SwapFloatLE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6593 sample2 = (float) ((((double) SDL_SwapFloatLE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6594 sample3 = (float) ((((double) SDL_SwapFloatLE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6595 sample4 = (float) ((((double) SDL_SwapFloatLE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6596 sample5 = (float) ((((double) SDL_SwapFloatLE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6597 sample6 = (float) ((((double) SDL_SwapFloatLE(src[6])) + ((double) last_sample6)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6598 sample7 = (float) ((((double) SDL_SwapFloatLE(src[7])) + ((double) last_sample7)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6599 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6600 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6601 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6602 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6603 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6604 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6605 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6606 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6607 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6608 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6609 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6610 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6611 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6612 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6613 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6614 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6615
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6616 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6617 SDL_Upsample_F32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6618 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6619 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6620 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6621 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6622
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6623 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6624 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6625 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6626 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6627 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6628 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6629 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6630 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6631 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6632 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6633 dst--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6634 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6635 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6636 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6637 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6638 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6639 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6640 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6641 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6642 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6643 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6644 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6645 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6646 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6647
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6648 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6649 SDL_Downsample_F32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6650 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6651 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6652 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32MSB, 1 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6653 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6654
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6655 const int srcsize = cvt->len_cvt - 64;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6656 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6657 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6658 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6659 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6660 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6661 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6662 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6663 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6664 src++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6665 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6666 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6667 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6668 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6669 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6670 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6671 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6672 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6673 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6674 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6675 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6676 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6677 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6678 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6679
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6680 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6681 SDL_Upsample_F32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6682 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6683 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6684 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6685 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6686
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6687 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6688 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6689 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6690 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6691 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6692 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6693 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6694 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6695 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6696 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6697 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6698 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6699 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6700 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6701 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6702 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6703 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6704 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6705 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6706 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6707 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6708 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6709 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6710 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6711 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6712 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6713 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6714 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6715 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6716
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6717 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6718 SDL_Downsample_F32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6719 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6720 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6721 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32MSB, 2 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6722 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6723
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6724 const int srcsize = cvt->len_cvt - 128;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6725 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6726 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6727 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6728 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6729 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6730 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6731 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6732 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6733 float last_sample1 = sample1;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6734 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6735 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6736 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6737 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6738 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6739 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6740 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6741 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6742 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6743 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6744 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6745 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6746 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6747 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6748 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6749 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6750 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6751 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6752 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6753
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6754 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6755 SDL_Upsample_F32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6756 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6757 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6758 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6759 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6760
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6761 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6762 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6763 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6764 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6765 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6766 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6767 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6768 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6769 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6770 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6771 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6772 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6773 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6774 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6775 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6776 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6777 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6778 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6779 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6780 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6781 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6782 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6783 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6784 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6785 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6786 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6787 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6788 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6789 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6790 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6791 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6792 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6793 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6794 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6795 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6796 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6797 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6798 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6799 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6800
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6801 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6802 SDL_Downsample_F32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6803 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6804 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6805 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32MSB, 4 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6806 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6807
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6808 const int srcsize = cvt->len_cvt - 256;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6809 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6810 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6811 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6812 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6813 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6814 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6815 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6816 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6817 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6818 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6819 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6820 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6821 float last_sample3 = sample3;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6822 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6823 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6824 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6825 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6826 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6827 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6828 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6829 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6830 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6831 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6832 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6833 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6834 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6835 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6836 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6837 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6838 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6839 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6840 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6841 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6842 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6843 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6844 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6845 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6846 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6847
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6848 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6849 SDL_Upsample_F32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6850 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6851 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6852 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6853 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6854
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6855 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6856 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6857 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6858 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6859 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6860 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6861 float sample5 = SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6862 float sample4 = SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6863 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6864 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6865 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6866 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6867 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6868 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6869 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6870 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6871 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6872 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6873 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6874 dst[5] = SDL_SwapFloatBE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6875 dst[4] = SDL_SwapFloatBE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6876 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6877 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6878 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6879 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6880 dst -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6881 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6882 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6883 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6884 sample5 = (float) ((((double) SDL_SwapFloatBE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6885 sample4 = (float) ((((double) SDL_SwapFloatBE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6886 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6887 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6888 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6889 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6890 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6891 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6892 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6893 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6894 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6895 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6896 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6897 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6898 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6899 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6900 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6901 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6902 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6903 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6904
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6905 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6906 SDL_Downsample_F32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6907 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6908 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6909 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32MSB, 6 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6910 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6911
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6912 const int srcsize = cvt->len_cvt - 384;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6913 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6914 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6915 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6916 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6917 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6918 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6919 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6920 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6921 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6922 float sample4 = SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6923 float sample5 = SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6924 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6925 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6926 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6927 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6928 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6929 float last_sample5 = sample5;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6930 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6931 src += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6932 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6933 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6934 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6935 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6936 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6937 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6938 dst[4] = SDL_SwapFloatBE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6939 dst[5] = SDL_SwapFloatBE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6940 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6941 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6942 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6943 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6944 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6945 sample4 = (float) ((((double) SDL_SwapFloatBE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6946 sample5 = (float) ((((double) SDL_SwapFloatBE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6947 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6948 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6949 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6950 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6951 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6952 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6953 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6954 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6955 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6956 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6957 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6958 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6959 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6960 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6961
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6962 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6963 SDL_Upsample_F32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6964 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
6965 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6966 fprintf(stderr, "Upsample arbitrary (x%f) AUDIO_F32MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6967 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6968
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6969 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6970 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6971 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6972 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6973 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6974 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6975 float sample7 = SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6976 float sample6 = SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6977 float sample5 = SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6978 float sample4 = SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6979 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6980 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6981 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6982 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6983 float last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6984 float last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6985 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6986 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6987 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6988 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6989 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6990 float last_sample0 = sample0;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
6991 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6992 dst[7] = SDL_SwapFloatBE(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6993 dst[6] = SDL_SwapFloatBE(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6994 dst[5] = SDL_SwapFloatBE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6995 dst[4] = SDL_SwapFloatBE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6996 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6997 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6998 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
6999 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7000 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7001 eps += srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7002 if ((eps << 1) >= dstsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7003 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7004 sample7 = (float) ((((double) SDL_SwapFloatBE(src[7])) + ((double) last_sample7)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7005 sample6 = (float) ((((double) SDL_SwapFloatBE(src[6])) + ((double) last_sample6)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7006 sample5 = (float) ((((double) SDL_SwapFloatBE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7007 sample4 = (float) ((((double) SDL_SwapFloatBE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7008 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7009 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7010 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7011 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7012 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7013 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7014 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7015 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7016 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7017 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7018 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7019 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7020 eps -= dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7021 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7022 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7023 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7024 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7025 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7026 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7027 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7028
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7029 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7030 SDL_Downsample_F32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7031 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7032 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7033 fprintf(stderr, "Downsample arbitrary (x%f) AUDIO_F32MSB, 8 channels.\n", cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7034 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7035
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7036 const int srcsize = cvt->len_cvt - 512;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7037 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7038 register int eps = 0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7039 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7040 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7041 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7042 float sample0 = SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7043 float sample1 = SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7044 float sample2 = SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7045 float sample3 = SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7046 float sample4 = SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7047 float sample5 = SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7048 float sample6 = SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7049 float sample7 = SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7050 float last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7051 float last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7052 float last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7053 float last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7054 float last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7055 float last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7056 float last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7057 float last_sample7 = sample7;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
7058 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7059 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7060 eps += dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7061 if ((eps << 1) >= srcsize) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7062 dst[0] = SDL_SwapFloatBE(sample0);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7063 dst[1] = SDL_SwapFloatBE(sample1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7064 dst[2] = SDL_SwapFloatBE(sample2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7065 dst[3] = SDL_SwapFloatBE(sample3);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7066 dst[4] = SDL_SwapFloatBE(sample4);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7067 dst[5] = SDL_SwapFloatBE(sample5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7068 dst[6] = SDL_SwapFloatBE(sample6);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7069 dst[7] = SDL_SwapFloatBE(sample7);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7070 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7071 sample0 = (float) ((((double) SDL_SwapFloatBE(src[0])) + ((double) last_sample0)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7072 sample1 = (float) ((((double) SDL_SwapFloatBE(src[1])) + ((double) last_sample1)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7073 sample2 = (float) ((((double) SDL_SwapFloatBE(src[2])) + ((double) last_sample2)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7074 sample3 = (float) ((((double) SDL_SwapFloatBE(src[3])) + ((double) last_sample3)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7075 sample4 = (float) ((((double) SDL_SwapFloatBE(src[4])) + ((double) last_sample4)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7076 sample5 = (float) ((((double) SDL_SwapFloatBE(src[5])) + ((double) last_sample5)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7077 sample6 = (float) ((((double) SDL_SwapFloatBE(src[6])) + ((double) last_sample6)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7078 sample7 = (float) ((((double) SDL_SwapFloatBE(src[7])) + ((double) last_sample7)) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7079 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7080 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7081 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7082 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7083 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7084 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7085 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7086 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7087 eps -= srcsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7088 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7089 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7090 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7091 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7092 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7093 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7094 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7095
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7096
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7097 #if !LESS_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7098
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7099 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7100 SDL_Upsample_U8_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7101 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7102 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7103 fprintf(stderr, "Upsample (x2) AUDIO_U8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7104 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7105
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7106 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7107 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7108 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7109 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7110 const Uint8 *target = ((const Uint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7111 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7112 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7113 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7114 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7115 dst[1] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7116 dst[0] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7117 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7118 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7119 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7120
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7121 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7122 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7123 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7124 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7125 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7126
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7127 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7128 SDL_Downsample_U8_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7129 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7130 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7131 fprintf(stderr, "Downsample (x2) AUDIO_U8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7132 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7133
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7134 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7135 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7136 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7137 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7138 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7139 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7140 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7141 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7142 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7143 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7144 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7145 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7146 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7147
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7148 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7149 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7150 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7151 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7152 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7153
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7154 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7155 SDL_Upsample_U8_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7156 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7157 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7158 fprintf(stderr, "Upsample (x4) AUDIO_U8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7159 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7160
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7161 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7162 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7163 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7164 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7165 const Uint8 *target = ((const Uint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7166 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7167 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7168 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7169 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7170 dst[3] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7171 dst[2] = (Uint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7172 dst[1] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7173 dst[0] = (Uint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7174 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7175 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7176 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7177
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7178 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7179 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7180 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7181 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7182 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7183
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7184 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7185 SDL_Downsample_U8_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7186 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7187 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7188 fprintf(stderr, "Downsample (x4) AUDIO_U8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7189 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7190
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7191 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7192 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7193 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7194 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7195 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7196 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7197 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7198 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7199 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7200 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7201 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7202 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7203 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7204
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7205 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7206 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7207 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7208 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7209 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7210
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7211 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7212 SDL_Upsample_U8_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7213 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7214 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7215 fprintf(stderr, "Upsample (x2) AUDIO_U8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7216 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7217
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7218 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7219 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7220 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7221 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7222 const Uint8 *target = ((const Uint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7223 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7224 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7225 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7226 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7227 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7228 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7229 dst[3] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7230 dst[2] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7231 dst[1] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7232 dst[0] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7233 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7234 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7235 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7236 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7237
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7238 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7239 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7240 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7241 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7242 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7243
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7244 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7245 SDL_Downsample_U8_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7246 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7247 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7248 fprintf(stderr, "Downsample (x2) AUDIO_U8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7249 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7250
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7251 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7252 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7253 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7254 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7255 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7256 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7257 Sint16 last_sample1 = (Sint16) src[1];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7258 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7259 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7260 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7261 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7262 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7263 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7264 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7265 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7266 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7267 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7268
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7269 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7270 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7271 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7272 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7273 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7274
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7275 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7276 SDL_Upsample_U8_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7277 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7278 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7279 fprintf(stderr, "Upsample (x4) AUDIO_U8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7280 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7281
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7282 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7283 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7284 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7285 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7286 const Uint8 *target = ((const Uint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7287 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7288 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7289 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7290 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7291 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7292 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7293 dst[7] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7294 dst[6] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7295 dst[5] = (Uint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7296 dst[4] = (Uint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7297 dst[3] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7298 dst[2] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7299 dst[1] = (Uint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7300 dst[0] = (Uint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7301 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7302 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7303 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7304 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7305
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7306 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7307 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7308 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7309 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7310 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7311
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7312 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7313 SDL_Downsample_U8_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7314 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7315 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7316 fprintf(stderr, "Downsample (x4) AUDIO_U8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7317 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7318
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7319 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7320 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7321 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7322 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7323 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7324 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7325 Sint16 last_sample1 = (Sint16) src[1];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7326 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7327 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7328 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7329 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7330 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7331 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7332 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7333 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7334 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7335 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7336
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7337 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7338 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7339 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7340 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7341 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7342
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7343 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7344 SDL_Upsample_U8_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7345 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7346 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7347 fprintf(stderr, "Upsample (x2) AUDIO_U8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7348 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7349
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7350 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7351 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7352 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7353 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7354 const Uint8 *target = ((const Uint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7355 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7356 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7357 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7358 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7359 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7360 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7361 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7362 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7363 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7364 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7365 dst[7] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7366 dst[6] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7367 dst[5] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7368 dst[4] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7369 dst[3] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7370 dst[2] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7371 dst[1] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7372 dst[0] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7373 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7374 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7375 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7376 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7377 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7378 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7379
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7380 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7381 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7382 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7383 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7384 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7385
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7386 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7387 SDL_Downsample_U8_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7388 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7389 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7390 fprintf(stderr, "Downsample (x2) AUDIO_U8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7391 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7392
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7393 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7394 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7395 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7396 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7397 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7398 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7399 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7400 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7401 Sint16 last_sample3 = (Sint16) src[3];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7402 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7403 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7404 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7405 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7406 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7407 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7408 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7409 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7410 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7411 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7412 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7413 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7414 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7415 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7416 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7417 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7418
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7419 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7420 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7421 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7422 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7423 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7424
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7425 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7426 SDL_Upsample_U8_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7427 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7428 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7429 fprintf(stderr, "Upsample (x4) AUDIO_U8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7430 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7431
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7432 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7433 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7434 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7435 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7436 const Uint8 *target = ((const Uint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7437 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7438 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7439 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7440 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7441 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7442 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7443 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7444 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7445 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7446 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7447 dst[15] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7448 dst[14] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7449 dst[13] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7450 dst[12] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7451 dst[11] = (Uint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7452 dst[10] = (Uint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7453 dst[9] = (Uint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7454 dst[8] = (Uint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7455 dst[7] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7456 dst[6] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7457 dst[5] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7458 dst[4] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7459 dst[3] = (Uint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7460 dst[2] = (Uint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7461 dst[1] = (Uint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7462 dst[0] = (Uint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7463 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7464 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7465 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7466 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7467 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7468 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7469
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7470 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7471 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7472 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7473 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7474 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7475
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7476 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7477 SDL_Downsample_U8_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7478 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7479 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7480 fprintf(stderr, "Downsample (x4) AUDIO_U8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7481 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7482
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7483 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7484 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7485 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7486 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7487 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7488 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7489 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7490 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7491 Sint16 last_sample3 = (Sint16) src[3];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7492 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7493 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7494 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7495 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7496 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7497 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7498 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7499 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7500 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7501 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7502 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7503 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7504 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7505 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7506 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7507 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7508
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7509 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7510 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7511 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7512 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7513 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7514
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7515 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7516 SDL_Upsample_U8_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7517 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7518 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7519 fprintf(stderr, "Upsample (x2) AUDIO_U8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7520 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7521
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7522 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7523 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7524 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7525 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7526 const Uint8 *target = ((const Uint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7527 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7528 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7529 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7530 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7531 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7532 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7533 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7534 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7535 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7536 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7537 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7538 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7539 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7540 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7541 dst[11] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7542 dst[10] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7543 dst[9] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7544 dst[8] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7545 dst[7] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7546 dst[6] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7547 dst[5] = (Uint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7548 dst[4] = (Uint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7549 dst[3] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7550 dst[2] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7551 dst[1] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7552 dst[0] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7553 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7554 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7555 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7556 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7557 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7558 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7559 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7560 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7561
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7562 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7563 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7564 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7565 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7566 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7567
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7568 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7569 SDL_Downsample_U8_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7570 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7571 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7572 fprintf(stderr, "Downsample (x2) AUDIO_U8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7573 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7574
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7575 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7576 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7577 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7578 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7579 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7580 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7581 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7582 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7583 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7584 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7585 Sint16 last_sample5 = (Sint16) src[5];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7586 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7587 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7588 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7589 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7590 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7591 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7592 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7593 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7594 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7595 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7596 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7597 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7598 dst[4] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7599 dst[5] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7600 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7601 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7602 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7603 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7604 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7605 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7606 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7607 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7608
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7609 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7610 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7611 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7612 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7613 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7614
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7615 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7616 SDL_Upsample_U8_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7617 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7618 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7619 fprintf(stderr, "Upsample (x4) AUDIO_U8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7620 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7621
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7622 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7623 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7624 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7625 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7626 const Uint8 *target = ((const Uint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7627 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7628 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7629 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7630 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7631 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7632 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7633 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7634 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7635 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7636 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7637 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7638 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7639 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7640 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7641 dst[23] = (Uint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7642 dst[22] = (Uint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7643 dst[21] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7644 dst[20] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7645 dst[19] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7646 dst[18] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7647 dst[17] = (Uint8) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7648 dst[16] = (Uint8) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7649 dst[15] = (Uint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7650 dst[14] = (Uint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7651 dst[13] = (Uint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7652 dst[12] = (Uint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7653 dst[11] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7654 dst[10] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7655 dst[9] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7656 dst[8] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7657 dst[7] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7658 dst[6] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7659 dst[5] = (Uint8) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7660 dst[4] = (Uint8) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7661 dst[3] = (Uint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7662 dst[2] = (Uint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7663 dst[1] = (Uint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7664 dst[0] = (Uint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7665 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7666 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7667 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7668 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7669 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7670 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7671 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7672 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7673
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7674 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7675 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7676 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7677 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7678 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7679
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7680 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7681 SDL_Downsample_U8_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7682 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7683 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7684 fprintf(stderr, "Downsample (x4) AUDIO_U8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7685 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7686
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7687 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7688 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7689 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7690 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7691 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7692 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7693 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7694 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7695 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7696 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7697 Sint16 last_sample5 = (Sint16) src[5];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7698 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7699 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7700 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7701 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7702 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7703 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7704 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7705 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7706 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7707 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7708 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7709 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7710 dst[4] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7711 dst[5] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7712 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7713 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7714 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7715 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7716 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7717 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7718 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7719 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7720
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7721 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7722 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7723 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7724 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7725 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7726
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7727 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7728 SDL_Upsample_U8_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7729 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7730 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7731 fprintf(stderr, "Upsample (x2) AUDIO_U8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7732 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7733
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7734 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7735 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7736 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7737 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7738 const Uint8 *target = ((const Uint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7739 Sint16 last_sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7740 Sint16 last_sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7741 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7742 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7743 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7744 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7745 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7746 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7747 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7748 const Sint16 sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7749 const Sint16 sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7750 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7751 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7752 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7753 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7754 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7755 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7756 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7757 dst[15] = (Uint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7758 dst[14] = (Uint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7759 dst[13] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7760 dst[12] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7761 dst[11] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7762 dst[10] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7763 dst[9] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7764 dst[8] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7765 dst[7] = (Uint8) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7766 dst[6] = (Uint8) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7767 dst[5] = (Uint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7768 dst[4] = (Uint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7769 dst[3] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7770 dst[2] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7771 dst[1] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7772 dst[0] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7773 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7774 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7775 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7776 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7777 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7778 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7779 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7780 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7781 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7782 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7783
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7784 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7785 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7786 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7787 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7788 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7789
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7790 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7791 SDL_Downsample_U8_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7792 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7793 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7794 fprintf(stderr, "Downsample (x2) AUDIO_U8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7795 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7796
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7797 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7798 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7799 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7800 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7801 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7802 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7803 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7804 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7805 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7806 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7807 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7808 Sint16 last_sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7809 Sint16 last_sample7 = (Sint16) src[7];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7810 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7811 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7812 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7813 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7814 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7815 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7816 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7817 const Sint16 sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7818 const Sint16 sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7819 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7820 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7821 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7822 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7823 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7824 dst[4] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7825 dst[5] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7826 dst[6] = (Uint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7827 dst[7] = (Uint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7828 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7829 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7830 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7831 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7832 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7833 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7834 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7835 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7836 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7837 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7838
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7839 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7840 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7841 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7842 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7843 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7844
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7845 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7846 SDL_Upsample_U8_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7847 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7848 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7849 fprintf(stderr, "Upsample (x4) AUDIO_U8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7850 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7851
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7852 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7853 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7854 Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7855 const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7856 const Uint8 *target = ((const Uint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7857 Sint16 last_sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7858 Sint16 last_sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7859 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7860 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7861 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7862 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7863 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7864 Sint16 last_sample0 = (Sint16) src[0];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7865 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7866 const Sint16 sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7867 const Sint16 sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7868 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7869 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7870 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7871 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7872 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7873 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7874 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7875 dst[31] = (Uint8) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7876 dst[30] = (Uint8) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7877 dst[29] = (Uint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7878 dst[28] = (Uint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7879 dst[27] = (Uint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7880 dst[26] = (Uint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7881 dst[25] = (Uint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7882 dst[24] = (Uint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7883 dst[23] = (Uint8) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7884 dst[22] = (Uint8) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7885 dst[21] = (Uint8) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7886 dst[20] = (Uint8) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7887 dst[19] = (Uint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7888 dst[18] = (Uint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7889 dst[17] = (Uint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7890 dst[16] = (Uint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7891 dst[15] = (Uint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7892 dst[14] = (Uint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7893 dst[13] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7894 dst[12] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7895 dst[11] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7896 dst[10] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7897 dst[9] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7898 dst[8] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7899 dst[7] = (Uint8) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7900 dst[6] = (Uint8) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7901 dst[5] = (Uint8) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7902 dst[4] = (Uint8) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7903 dst[3] = (Uint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7904 dst[2] = (Uint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7905 dst[1] = (Uint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7906 dst[0] = (Uint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7907 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7908 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7909 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7910 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7911 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7912 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7913 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7914 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7915 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7916 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7917
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7918 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7919 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7920 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7921 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7922 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7923
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7924 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7925 SDL_Downsample_U8_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7926 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7927 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7928 fprintf(stderr, "Downsample (x4) AUDIO_U8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7929 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7930
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7931 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7932 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7933 Uint8 *dst = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7934 const Uint8 *src = (Uint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7935 const Uint8 *target = (const Uint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7936 Sint16 last_sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7937 Sint16 last_sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7938 Sint16 last_sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7939 Sint16 last_sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7940 Sint16 last_sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7941 Sint16 last_sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7942 Sint16 last_sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7943 Sint16 last_sample7 = (Sint16) src[7];
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7944 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7945 const Sint16 sample0 = (Sint16) src[0];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7946 const Sint16 sample1 = (Sint16) src[1];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7947 const Sint16 sample2 = (Sint16) src[2];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7948 const Sint16 sample3 = (Sint16) src[3];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7949 const Sint16 sample4 = (Sint16) src[4];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7950 const Sint16 sample5 = (Sint16) src[5];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7951 const Sint16 sample6 = (Sint16) src[6];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7952 const Sint16 sample7 = (Sint16) src[7];
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7953 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7954 dst[0] = (Uint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7955 dst[1] = (Uint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7956 dst[2] = (Uint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7957 dst[3] = (Uint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7958 dst[4] = (Uint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7959 dst[5] = (Uint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7960 dst[6] = (Uint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7961 dst[7] = (Uint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7962 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7963 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7964 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7965 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7966 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7967 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7968 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7969 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7970 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7971 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7972
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7973 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7974 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7975 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7976 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7977 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7978
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7979 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7980 SDL_Upsample_S8_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7981 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
7982 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7983 fprintf(stderr, "Upsample (x2) AUDIO_S8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7984 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7985
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7986 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7987 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7988 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7989 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7990 const Sint8 *target = ((const Sint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7991 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
7992 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7993 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7994 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7995 dst[1] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7996 dst[0] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7997 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7998 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
7999 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8000
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8001 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8002 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8003 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8004 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8005 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8006
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8007 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8008 SDL_Downsample_S8_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8009 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8010 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8011 fprintf(stderr, "Downsample (x2) AUDIO_S8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8012 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8013
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8014 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8015 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8016 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8017 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8018 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8019 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8020 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8021 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8022 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8023 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8024 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8025 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8026 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8027
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8028 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8029 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8030 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8031 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8032 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8033
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8034 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8035 SDL_Upsample_S8_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8036 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8037 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8038 fprintf(stderr, "Upsample (x4) AUDIO_S8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8039 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8040
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8041 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8042 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8043 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8044 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8045 const Sint8 *target = ((const Sint8 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8046 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8047 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8048 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8049 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8050 dst[3] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8051 dst[2] = (Sint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8052 dst[1] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8053 dst[0] = (Sint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8054 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8055 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8056 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8057
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8058 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8059 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8060 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8061 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8062 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8063
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8064 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8065 SDL_Downsample_S8_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8066 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8067 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8068 fprintf(stderr, "Downsample (x4) AUDIO_S8, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8069 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8070
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8071 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8072 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8073 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8074 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8075 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8076 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8077 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8078 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8079 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8080 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8081 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8082 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8083 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8084
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8085 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8086 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8087 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8088 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8089 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8090
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8091 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8092 SDL_Upsample_S8_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8093 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8094 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8095 fprintf(stderr, "Upsample (x2) AUDIO_S8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8096 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8097
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8098 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8099 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8100 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8101 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8102 const Sint8 *target = ((const Sint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8103 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8104 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8105 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8106 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8107 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8108 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8109 dst[3] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8110 dst[2] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8111 dst[1] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8112 dst[0] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8113 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8114 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8115 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8116 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8117
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8118 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8119 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8120 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8121 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8122 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8123
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8124 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8125 SDL_Downsample_S8_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8126 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8127 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8128 fprintf(stderr, "Downsample (x2) AUDIO_S8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8129 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8130
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8131 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8132 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8133 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8134 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8135 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8136 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8137 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8138 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8139 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8140 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8141 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8142 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8143 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8144 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8145 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8146 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8147 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8148
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8149 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8150 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8151 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8152 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8153 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8154
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8155 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8156 SDL_Upsample_S8_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8157 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8158 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8159 fprintf(stderr, "Upsample (x4) AUDIO_S8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8160 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8161
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8162 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8163 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8164 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8165 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8166 const Sint8 *target = ((const Sint8 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8167 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8168 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8169 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8170 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8171 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8172 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8173 dst[7] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8174 dst[6] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8175 dst[5] = (Sint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8176 dst[4] = (Sint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8177 dst[3] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8178 dst[2] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8179 dst[1] = (Sint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8180 dst[0] = (Sint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8181 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8182 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8183 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8184 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8185
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8186 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8187 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8188 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8189 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8190 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8191
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8192 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8193 SDL_Downsample_S8_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8194 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8195 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8196 fprintf(stderr, "Downsample (x4) AUDIO_S8, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8197 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8198
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8199 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8200 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8201 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8202 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8203 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8204 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8205 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8206 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8207 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8208 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8209 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8210 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8211 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8212 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8213 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8214 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8215 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8216
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8217 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8218 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8219 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8220 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8221 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8222
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8223 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8224 SDL_Upsample_S8_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8225 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8226 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8227 fprintf(stderr, "Upsample (x2) AUDIO_S8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8228 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8229
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8230 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8231 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8232 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8233 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8234 const Sint8 *target = ((const Sint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8235 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8236 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8237 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8238 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8239 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8240 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8241 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8242 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8243 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8244 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8245 dst[7] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8246 dst[6] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8247 dst[5] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8248 dst[4] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8249 dst[3] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8250 dst[2] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8251 dst[1] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8252 dst[0] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8253 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8254 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8255 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8256 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8257 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8258 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8259
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8260 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8261 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8262 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8263 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8264 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8265
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8266 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8267 SDL_Downsample_S8_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8268 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8269 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8270 fprintf(stderr, "Downsample (x2) AUDIO_S8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8271 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8272
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8273 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8274 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8275 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8276 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8277 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8278 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8279 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8280 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8281 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8282 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8283 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8284 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8285 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8286 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8287 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8288 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8289 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8290 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8291 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8292 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8293 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8294 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8295 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8296 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8297 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8298
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8299 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8300 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8301 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8302 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8303 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8304
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8305 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8306 SDL_Upsample_S8_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8307 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8308 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8309 fprintf(stderr, "Upsample (x4) AUDIO_S8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8310 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8311
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8312 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8313 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8314 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8315 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8316 const Sint8 *target = ((const Sint8 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8317 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8318 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8319 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8320 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8321 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8322 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8323 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8324 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8325 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8326 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8327 dst[15] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8328 dst[14] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8329 dst[13] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8330 dst[12] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8331 dst[11] = (Sint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8332 dst[10] = (Sint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8333 dst[9] = (Sint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8334 dst[8] = (Sint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8335 dst[7] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8336 dst[6] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8337 dst[5] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8338 dst[4] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8339 dst[3] = (Sint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8340 dst[2] = (Sint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8341 dst[1] = (Sint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8342 dst[0] = (Sint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8343 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8344 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8345 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8346 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8347 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8348 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8349
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8350 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8351 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8352 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8353 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8354 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8355
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8356 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8357 SDL_Downsample_S8_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8358 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8359 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8360 fprintf(stderr, "Downsample (x4) AUDIO_S8, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8361 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8362
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8363 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8364 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8365 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8366 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8367 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8368 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8369 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8370 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8371 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8372 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8373 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8374 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8375 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8376 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8377 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8378 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8379 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8380 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8381 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8382 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8383 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8384 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8385 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8386 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8387 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8388
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8389 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8390 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8391 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8392 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8393 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8394
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8395 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8396 SDL_Upsample_S8_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8397 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8398 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8399 fprintf(stderr, "Upsample (x2) AUDIO_S8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8400 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8401
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8402 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8403 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8404 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8405 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8406 const Sint8 *target = ((const Sint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8407 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8408 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8409 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8410 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8411 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8412 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8413 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8414 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8415 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8416 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8417 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8418 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8419 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8420 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8421 dst[11] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8422 dst[10] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8423 dst[9] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8424 dst[8] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8425 dst[7] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8426 dst[6] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8427 dst[5] = (Sint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8428 dst[4] = (Sint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8429 dst[3] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8430 dst[2] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8431 dst[1] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8432 dst[0] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8433 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8434 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8435 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8436 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8437 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8438 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8439 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8440 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8441
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8442 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8443 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8444 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8445 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8446 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8447
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8448 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8449 SDL_Downsample_S8_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8450 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8451 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8452 fprintf(stderr, "Downsample (x2) AUDIO_S8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8453 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8454
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8455 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8456 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8457 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8458 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8459 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8460 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8461 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8462 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8463 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8464 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8465 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8466 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8467 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8468 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8469 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8470 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8471 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8472 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8473 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8474 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8475 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8476 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8477 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8478 dst[4] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8479 dst[5] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8480 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8481 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8482 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8483 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8484 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8485 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8486 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8487 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8488
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8489 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8490 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8491 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8492 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8493 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8494
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8495 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8496 SDL_Upsample_S8_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8497 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8498 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8499 fprintf(stderr, "Upsample (x4) AUDIO_S8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8500 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8501
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8502 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8503 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8504 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8505 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8506 const Sint8 *target = ((const Sint8 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8507 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8508 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8509 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8510 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8511 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8512 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8513 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8514 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8515 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8516 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8517 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8518 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8519 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8520 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8521 dst[23] = (Sint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8522 dst[22] = (Sint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8523 dst[21] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8524 dst[20] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8525 dst[19] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8526 dst[18] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8527 dst[17] = (Sint8) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8528 dst[16] = (Sint8) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8529 dst[15] = (Sint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8530 dst[14] = (Sint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8531 dst[13] = (Sint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8532 dst[12] = (Sint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8533 dst[11] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8534 dst[10] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8535 dst[9] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8536 dst[8] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8537 dst[7] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8538 dst[6] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8539 dst[5] = (Sint8) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8540 dst[4] = (Sint8) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8541 dst[3] = (Sint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8542 dst[2] = (Sint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8543 dst[1] = (Sint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8544 dst[0] = (Sint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8545 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8546 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8547 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8548 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8549 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8550 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8551 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8552 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8553
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8554 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8555 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8556 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8557 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8558 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8559
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8560 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8561 SDL_Downsample_S8_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8562 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8563 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8564 fprintf(stderr, "Downsample (x4) AUDIO_S8, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8565 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8566
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8567 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8568 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8569 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8570 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8571 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8572 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8573 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8574 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8575 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8576 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8577 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8578 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8579 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8580 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8581 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8582 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8583 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8584 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8585 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8586 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8587 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8588 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8589 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8590 dst[4] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8591 dst[5] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8592 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8593 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8594 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8595 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8596 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8597 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8598 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8599 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8600
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8601 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8602 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8603 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8604 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8605 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8606
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8607 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8608 SDL_Upsample_S8_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8609 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8610 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8611 fprintf(stderr, "Upsample (x2) AUDIO_S8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8612 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8613
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8614 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8615 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8616 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8617 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8618 const Sint8 *target = ((const Sint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8619 Sint16 last_sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8620 Sint16 last_sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8621 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8622 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8623 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8624 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8625 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8626 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8627 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8628 const Sint16 sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8629 const Sint16 sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8630 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8631 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8632 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8633 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8634 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8635 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8636 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8637 dst[15] = (Sint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8638 dst[14] = (Sint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8639 dst[13] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8640 dst[12] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8641 dst[11] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8642 dst[10] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8643 dst[9] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8644 dst[8] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8645 dst[7] = (Sint8) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8646 dst[6] = (Sint8) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8647 dst[5] = (Sint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8648 dst[4] = (Sint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8649 dst[3] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8650 dst[2] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8651 dst[1] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8652 dst[0] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8653 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8654 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8655 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8656 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8657 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8658 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8659 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8660 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8661 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8662 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8663
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8664 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8665 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8666 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8667 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8668 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8669
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8670 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8671 SDL_Downsample_S8_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8672 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8673 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8674 fprintf(stderr, "Downsample (x2) AUDIO_S8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8675 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8676
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8677 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8678 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8679 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8680 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8681 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8682 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8683 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8684 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8685 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8686 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8687 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8688 Sint16 last_sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8689 Sint16 last_sample7 = (Sint16) ((Sint8) src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8690 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8691 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8692 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8693 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8694 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8695 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8696 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8697 const Sint16 sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8698 const Sint16 sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8699 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8700 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8701 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8702 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8703 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8704 dst[4] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8705 dst[5] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8706 dst[6] = (Sint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8707 dst[7] = (Sint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8708 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8709 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8710 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8711 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8712 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8713 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8714 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8715 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8716 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8717 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8718
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8719 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8720 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8721 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8722 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8723 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8724
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8725 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8726 SDL_Upsample_S8_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8727 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8728 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8729 fprintf(stderr, "Upsample (x4) AUDIO_S8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8730 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8731
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8732 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8733 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8734 Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8735 const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8736 const Sint8 *target = ((const Sint8 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8737 Sint16 last_sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8738 Sint16 last_sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8739 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8740 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8741 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8742 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8743 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8744 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8745 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8746 const Sint16 sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8747 const Sint16 sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8748 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8749 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8750 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8751 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8752 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8753 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8754 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8755 dst[31] = (Sint8) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8756 dst[30] = (Sint8) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8757 dst[29] = (Sint8) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8758 dst[28] = (Sint8) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8759 dst[27] = (Sint8) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8760 dst[26] = (Sint8) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8761 dst[25] = (Sint8) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8762 dst[24] = (Sint8) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8763 dst[23] = (Sint8) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8764 dst[22] = (Sint8) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8765 dst[21] = (Sint8) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8766 dst[20] = (Sint8) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8767 dst[19] = (Sint8) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8768 dst[18] = (Sint8) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8769 dst[17] = (Sint8) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8770 dst[16] = (Sint8) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8771 dst[15] = (Sint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8772 dst[14] = (Sint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8773 dst[13] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8774 dst[12] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8775 dst[11] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8776 dst[10] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8777 dst[9] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8778 dst[8] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8779 dst[7] = (Sint8) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8780 dst[6] = (Sint8) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8781 dst[5] = (Sint8) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8782 dst[4] = (Sint8) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8783 dst[3] = (Sint8) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8784 dst[2] = (Sint8) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8785 dst[1] = (Sint8) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8786 dst[0] = (Sint8) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8787 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8788 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8789 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8790 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8791 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8792 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8793 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8794 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8795 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8796 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8797
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8798 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8799 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8800 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8801 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8802 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8803
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8804 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8805 SDL_Downsample_S8_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8806 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8807 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8808 fprintf(stderr, "Downsample (x4) AUDIO_S8, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8809 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8810
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8811 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8812 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8813 Sint8 *dst = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8814 const Sint8 *src = (Sint8 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8815 const Sint8 *target = (const Sint8 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8816 Sint16 last_sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8817 Sint16 last_sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8818 Sint16 last_sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8819 Sint16 last_sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8820 Sint16 last_sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8821 Sint16 last_sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8822 Sint16 last_sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8823 Sint16 last_sample7 = (Sint16) ((Sint8) src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8824 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8825 const Sint16 sample0 = (Sint16) ((Sint8) src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8826 const Sint16 sample1 = (Sint16) ((Sint8) src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8827 const Sint16 sample2 = (Sint16) ((Sint8) src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8828 const Sint16 sample3 = (Sint16) ((Sint8) src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8829 const Sint16 sample4 = (Sint16) ((Sint8) src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8830 const Sint16 sample5 = (Sint16) ((Sint8) src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8831 const Sint16 sample6 = (Sint16) ((Sint8) src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8832 const Sint16 sample7 = (Sint16) ((Sint8) src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8833 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8834 dst[0] = (Sint8) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8835 dst[1] = (Sint8) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8836 dst[2] = (Sint8) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8837 dst[3] = (Sint8) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8838 dst[4] = (Sint8) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8839 dst[5] = (Sint8) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8840 dst[6] = (Sint8) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8841 dst[7] = (Sint8) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8842 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8843 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8844 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8845 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8846 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8847 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8848 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8849 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8850 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8851 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8852
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8853 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8854 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8855 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8856 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8857 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8858
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8859 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8860 SDL_Upsample_U16LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8861 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8862 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8863 fprintf(stderr, "Upsample (x2) AUDIO_U16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8864 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8865
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8866 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8867 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8868 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8869 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8870 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8871 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8872 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8873 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8874 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8875 dst[1] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8876 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8877 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8878 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8879 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8880
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8881 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8882 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8883 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8884 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8885 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8886
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8887 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8888 SDL_Downsample_U16LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8889 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8890 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8891 fprintf(stderr, "Downsample (x2) AUDIO_U16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8892 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8893
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8894 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8895 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8896 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8897 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8898 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8899 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8900 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8901 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8902 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8903 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8904 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8905 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8906 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8907
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8908 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8909 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8910 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8911 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8912 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8913
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8914 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8915 SDL_Upsample_U16LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8916 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8917 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8918 fprintf(stderr, "Upsample (x4) AUDIO_U16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8919 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8920
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8921 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8922 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8923 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8924 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8925 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8926 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8927 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8928 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8929 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8930 dst[3] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8931 dst[2] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8932 dst[1] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8933 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8934 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8935 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8936 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8937
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8938 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8939 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8940 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8941 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8942 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8943
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8944 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8945 SDL_Downsample_U16LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8946 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8947 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8948 fprintf(stderr, "Downsample (x4) AUDIO_U16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8949 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8950
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8951 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8952 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8953 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8954 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8955 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8956 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8957 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8958 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8959 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8960 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8961 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8962 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8963 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8964
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8965 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8966 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8967 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8968 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8969 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8970
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8971 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8972 SDL_Upsample_U16LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8973 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
8974 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8975 fprintf(stderr, "Upsample (x2) AUDIO_U16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8976 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8977
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8978 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8979 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8980 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8981 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8982 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8983 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8984 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
8985 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8986 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8987 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8988 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8989 dst[3] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8990 dst[2] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8991 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8992 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8993 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8994 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8995 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8996 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8997
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8998 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
8999 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9000 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9001 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9002 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9003
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9004 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9005 SDL_Downsample_U16LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9006 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9007 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9008 fprintf(stderr, "Downsample (x2) AUDIO_U16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9009 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9010
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9011 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9012 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9013 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9014 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9015 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9016 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9017 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9018 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9019 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9020 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9021 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9022 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9023 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9024 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9025 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9026 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9027 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9028
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9029 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9030 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9031 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9032 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9033 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9034
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9035 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9036 SDL_Upsample_U16LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9037 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9038 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9039 fprintf(stderr, "Upsample (x4) AUDIO_U16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9040 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9041
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9042 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9043 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9044 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9045 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9046 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9047 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9048 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9049 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9050 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9051 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9052 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9053 dst[7] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9054 dst[6] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9055 dst[5] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9056 dst[4] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9057 dst[3] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9058 dst[2] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9059 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9060 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9061 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9062 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9063 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9064 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9065
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9066 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9067 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9068 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9069 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9070 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9071
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9072 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9073 SDL_Downsample_U16LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9074 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9075 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9076 fprintf(stderr, "Downsample (x4) AUDIO_U16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9077 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9078
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9079 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9080 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9081 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9082 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9083 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9084 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9085 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9086 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9087 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9088 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9089 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9090 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9091 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9092 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9093 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9094 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9095 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9096
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9097 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9098 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9099 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9100 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9101 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9102
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9103 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9104 SDL_Upsample_U16LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9105 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9106 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9107 fprintf(stderr, "Upsample (x2) AUDIO_U16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9108 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9109
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9110 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9111 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9112 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9113 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9114 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9115 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9116 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9117 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9118 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9119 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9120 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9121 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9122 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9123 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9124 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9125 dst[7] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9126 dst[6] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9127 dst[5] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9128 dst[4] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9129 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9130 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9131 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9132 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9133 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9134 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9135 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9136 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9137 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9138 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9139
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9140 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9141 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9142 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9143 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9144 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9145
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9146 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9147 SDL_Downsample_U16LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9148 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9149 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9150 fprintf(stderr, "Downsample (x2) AUDIO_U16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9151 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9152
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9153 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9154 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9155 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9156 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9157 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9158 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9159 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9160 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9161 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9162 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9163 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9164 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9165 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9166 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9167 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9168 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9169 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9170 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9171 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9172 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9173 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9174 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9175 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9176 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9177 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9178
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9179 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9180 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9181 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9182 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9183 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9184
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9185 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9186 SDL_Upsample_U16LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9187 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9188 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9189 fprintf(stderr, "Upsample (x4) AUDIO_U16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9190 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9191
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9192 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9193 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9194 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9195 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9196 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9197 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9198 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9199 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9200 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9201 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9202 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9203 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9204 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9205 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9206 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9207 dst[15] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9208 dst[14] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9209 dst[13] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9210 dst[12] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9211 dst[11] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9212 dst[10] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9213 dst[9] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9214 dst[8] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9215 dst[7] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9216 dst[6] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9217 dst[5] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9218 dst[4] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9219 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9220 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9221 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9222 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9223 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9224 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9225 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9226 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9227 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9228 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9229
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9230 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9231 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9232 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9233 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9234 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9235
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9236 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9237 SDL_Downsample_U16LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9238 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9239 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9240 fprintf(stderr, "Downsample (x4) AUDIO_U16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9241 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9242
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9243 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9244 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9245 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9246 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9247 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9248 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9249 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9250 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9251 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9252 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9253 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9254 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9255 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9256 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9257 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9258 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9259 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9260 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9261 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9262 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9263 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9264 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9265 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9266 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9267 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9268
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9269 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9270 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9271 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9272 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9273 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9274
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9275 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9276 SDL_Upsample_U16LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9277 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9278 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9279 fprintf(stderr, "Upsample (x2) AUDIO_U16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9280 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9281
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9282 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9283 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9284 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9285 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9286 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9287 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9288 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9289 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9290 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9291 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9292 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9293 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9294 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9295 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9296 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9297 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9298 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9299 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9300 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9301 dst[11] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9302 dst[10] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9303 dst[9] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9304 dst[8] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9305 dst[7] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9306 dst[6] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9307 dst[5] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9308 dst[4] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9309 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9310 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9311 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9312 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9313 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9314 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9315 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9316 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9317 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9318 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9319 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9320 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9321
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9322 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9323 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9324 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9325 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9326 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9327
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9328 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9329 SDL_Downsample_U16LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9330 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9331 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9332 fprintf(stderr, "Downsample (x2) AUDIO_U16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9333 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9334
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9335 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9336 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9337 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9338 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9339 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9340 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9341 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9342 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9343 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9344 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9345 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9346 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9347 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9348 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9349 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9350 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9351 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9352 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9353 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9354 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9355 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9356 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9357 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9358 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9359 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9360 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9361 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9362 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9363 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9364 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9365 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9366 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9367 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9368
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9369 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9370 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9371 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9372 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9373 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9374
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9375 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9376 SDL_Upsample_U16LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9377 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9378 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9379 fprintf(stderr, "Upsample (x4) AUDIO_U16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9380 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9381
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9382 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9383 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9384 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9385 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9386 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9387 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9388 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9389 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9390 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9391 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9392 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9393 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9394 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9395 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9396 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9397 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9398 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9399 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9400 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9401 dst[23] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9402 dst[22] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9403 dst[21] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9404 dst[20] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9405 dst[19] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9406 dst[18] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9407 dst[17] = (Uint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9408 dst[16] = (Uint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9409 dst[15] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9410 dst[14] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9411 dst[13] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9412 dst[12] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9413 dst[11] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9414 dst[10] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9415 dst[9] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9416 dst[8] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9417 dst[7] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9418 dst[6] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9419 dst[5] = (Uint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9420 dst[4] = (Uint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9421 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9422 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9423 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9424 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9425 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9426 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9427 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9428 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9429 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9430 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9431 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9432 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9433
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9434 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9435 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9436 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9437 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9438 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9439
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9440 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9441 SDL_Downsample_U16LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9442 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9443 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9444 fprintf(stderr, "Downsample (x4) AUDIO_U16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9445 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9446
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9447 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9448 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9449 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9450 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9451 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9452 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9453 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9454 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9455 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9456 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9457 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9458 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9459 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9460 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9461 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9462 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9463 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9464 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9465 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9466 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9467 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9468 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9469 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9470 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9471 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9472 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9473 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9474 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9475 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9476 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9477 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9478 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9479 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9480
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9481 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9482 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9483 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9484 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9485 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9486
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9487 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9488 SDL_Upsample_U16LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9489 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9490 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9491 fprintf(stderr, "Upsample (x2) AUDIO_U16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9492 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9493
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9494 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9495 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9496 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9497 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9498 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9499 Sint32 last_sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9500 Sint32 last_sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9501 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9502 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9503 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9504 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9505 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9506 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9507 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9508 const Sint32 sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9509 const Sint32 sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9510 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9511 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9512 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9513 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9514 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9515 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9516 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9517 dst[15] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9518 dst[14] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9519 dst[13] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9520 dst[12] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9521 dst[11] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9522 dst[10] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9523 dst[9] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9524 dst[8] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9525 dst[7] = (Uint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9526 dst[6] = (Uint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9527 dst[5] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9528 dst[4] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9529 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9530 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9531 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9532 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9533 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9534 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9535 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9536 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9537 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9538 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9539 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9540 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9541 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9542 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9543
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9544 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9545 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9546 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9547 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9548 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9549
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9550 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9551 SDL_Downsample_U16LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9552 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9553 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9554 fprintf(stderr, "Downsample (x2) AUDIO_U16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9555 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9556
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9557 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9558 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9559 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9560 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9561 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9562 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9563 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9564 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9565 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9566 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9567 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9568 Sint32 last_sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9569 Sint32 last_sample7 = (Sint32) SDL_SwapLE16(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9570 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9571 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9572 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9573 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9574 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9575 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9576 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9577 const Sint32 sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9578 const Sint32 sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9579 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9580 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9581 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9582 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9583 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9584 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9585 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9586 dst[6] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9587 dst[7] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9588 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9589 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9590 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9591 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9592 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9593 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9594 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9595 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9596 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9597 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9598
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9599 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9600 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9601 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9602 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9603 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9604
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9605 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9606 SDL_Upsample_U16LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9607 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9608 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9609 fprintf(stderr, "Upsample (x4) AUDIO_U16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9610 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9611
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9612 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9613 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9614 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9615 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9616 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9617 Sint32 last_sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9618 Sint32 last_sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9619 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9620 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9621 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9622 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9623 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9624 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9625 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9626 const Sint32 sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9627 const Sint32 sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9628 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9629 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9630 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9631 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9632 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9633 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9634 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9635 dst[31] = (Uint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9636 dst[30] = (Uint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9637 dst[29] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9638 dst[28] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9639 dst[27] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9640 dst[26] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9641 dst[25] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9642 dst[24] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9643 dst[23] = (Uint16) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9644 dst[22] = (Uint16) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9645 dst[21] = (Uint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9646 dst[20] = (Uint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9647 dst[19] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9648 dst[18] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9649 dst[17] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9650 dst[16] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9651 dst[15] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9652 dst[14] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9653 dst[13] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9654 dst[12] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9655 dst[11] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9656 dst[10] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9657 dst[9] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9658 dst[8] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9659 dst[7] = (Uint16) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9660 dst[6] = (Uint16) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9661 dst[5] = (Uint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9662 dst[4] = (Uint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9663 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9664 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9665 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9666 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9667 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9668 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9669 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9670 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9671 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9672 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9673 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9674 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9675 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9676 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9677
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9678 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9679 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9680 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9681 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9682 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9683
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9684 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9685 SDL_Downsample_U16LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9686 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9687 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9688 fprintf(stderr, "Downsample (x4) AUDIO_U16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9689 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9690
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9691 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9692 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9693 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9694 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9695 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9696 Sint32 last_sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9697 Sint32 last_sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9698 Sint32 last_sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9699 Sint32 last_sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9700 Sint32 last_sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9701 Sint32 last_sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9702 Sint32 last_sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9703 Sint32 last_sample7 = (Sint32) SDL_SwapLE16(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9704 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9705 const Sint32 sample0 = (Sint32) SDL_SwapLE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9706 const Sint32 sample1 = (Sint32) SDL_SwapLE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9707 const Sint32 sample2 = (Sint32) SDL_SwapLE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9708 const Sint32 sample3 = (Sint32) SDL_SwapLE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9709 const Sint32 sample4 = (Sint32) SDL_SwapLE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9710 const Sint32 sample5 = (Sint32) SDL_SwapLE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9711 const Sint32 sample6 = (Sint32) SDL_SwapLE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9712 const Sint32 sample7 = (Sint32) SDL_SwapLE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9713 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9714 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9715 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9716 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9717 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9718 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9719 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9720 dst[6] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9721 dst[7] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9722 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9723 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9724 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9725 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9726 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9727 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9728 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9729 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9730 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9731 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9732
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9733 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9734 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9735 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9736 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9737 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9738
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9739 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9740 SDL_Upsample_S16LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9741 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9742 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9743 fprintf(stderr, "Upsample (x2) AUDIO_S16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9744 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9745
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9746 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9747 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9748 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9749 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9750 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9751 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9752 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9753 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9754 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9755 dst[1] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9756 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9757 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9758 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9759 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9760
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9761 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9762 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9763 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9764 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9765 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9766
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9767 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9768 SDL_Downsample_S16LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9769 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9770 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9771 fprintf(stderr, "Downsample (x2) AUDIO_S16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9772 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9773
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9774 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9775 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9776 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9777 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9778 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9779 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9780 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9781 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9782 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9783 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9784 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9785 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9786 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9787
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9788 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9789 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9790 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9791 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9792 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9793
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9794 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9795 SDL_Upsample_S16LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9796 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9797 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9798 fprintf(stderr, "Upsample (x4) AUDIO_S16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9799 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9800
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9801 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9802 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9803 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9804 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9805 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9806 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9807 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9808 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9809 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9810 dst[3] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9811 dst[2] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9812 dst[1] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9813 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9814 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9815 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9816 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9817
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9818 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9819 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9820 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9821 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9822 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9823
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9824 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9825 SDL_Downsample_S16LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9826 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9827 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9828 fprintf(stderr, "Downsample (x4) AUDIO_S16LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9829 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9830
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9831 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9832 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9833 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9834 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9835 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9836 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9837 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9838 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9839 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9840 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9841 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9842 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9843 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9844
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9845 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9846 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9847 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9848 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9849 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9850
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9851 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9852 SDL_Upsample_S16LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9853 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9854 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9855 fprintf(stderr, "Upsample (x2) AUDIO_S16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9856 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9857
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9858 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9859 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9860 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9861 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9862 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9863 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9864 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9865 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9866 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9867 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9868 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9869 dst[3] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9870 dst[2] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9871 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9872 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9873 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9874 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9875 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9876 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9877
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9878 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9879 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9880 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9881 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9882 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9883
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9884 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9885 SDL_Downsample_S16LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9886 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9887 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9888 fprintf(stderr, "Downsample (x2) AUDIO_S16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9889 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9890
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9891 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9892 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9893 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9894 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9895 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9896 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9897 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9898 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9899 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9900 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9901 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9902 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9903 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9904 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9905 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9906 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9907 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9908
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9909 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9910 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9911 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9912 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9913 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9914
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9915 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9916 SDL_Upsample_S16LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9917 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9918 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9919 fprintf(stderr, "Upsample (x4) AUDIO_S16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9920 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9921
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9922 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9923 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9924 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9925 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9926 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9927 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9928 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9929 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9930 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9931 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9932 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9933 dst[7] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9934 dst[6] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9935 dst[5] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9936 dst[4] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9937 dst[3] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9938 dst[2] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9939 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9940 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9941 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9942 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9943 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9944 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9945
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9946 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9947 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9948 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9949 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9950 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9951
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9952 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9953 SDL_Downsample_S16LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9954 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9955 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9956 fprintf(stderr, "Downsample (x4) AUDIO_S16LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9957 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9958
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9959 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9960 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9961 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9962 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9963 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9964 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9965 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9966 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9967 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9968 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9969 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9970 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9971 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9972 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9973 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9974 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9975 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9976
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9977 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9978 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9979 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9980 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9981 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9982
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9983 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9984 SDL_Upsample_S16LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9985 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
9986 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9987 fprintf(stderr, "Upsample (x2) AUDIO_S16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9988 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9989
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9990 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9991 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9992 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9993 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9994 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9995 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9996 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9997 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
9998 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
9999 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10000 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10001 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10002 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10003 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10004 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10005 dst[7] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10006 dst[6] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10007 dst[5] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10008 dst[4] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10009 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10010 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10011 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10012 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10013 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10014 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10015 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10016 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10017 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10018 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10019
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10020 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10021 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10022 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10023 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10024 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10025
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10026 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10027 SDL_Downsample_S16LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10028 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10029 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10030 fprintf(stderr, "Downsample (x2) AUDIO_S16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10031 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10032
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10033 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10034 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10035 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10036 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10037 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10038 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10039 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10040 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10041 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10042 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10043 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10044 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10045 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10046 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10047 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10048 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10049 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10050 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10051 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10052 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10053 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10054 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10055 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10056 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10057 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10058
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10059 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10060 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10061 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10062 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10063 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10064
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10065 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10066 SDL_Upsample_S16LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10067 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10068 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10069 fprintf(stderr, "Upsample (x4) AUDIO_S16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10070 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10071
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10072 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10073 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10074 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10075 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10076 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10077 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10078 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10079 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10080 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10081 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10082 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10083 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10084 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10085 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10086 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10087 dst[15] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10088 dst[14] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10089 dst[13] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10090 dst[12] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10091 dst[11] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10092 dst[10] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10093 dst[9] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10094 dst[8] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10095 dst[7] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10096 dst[6] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10097 dst[5] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10098 dst[4] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10099 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10100 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10101 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10102 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10103 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10104 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10105 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10106 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10107 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10108 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10109
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10110 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10111 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10112 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10113 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10114 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10115
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10116 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10117 SDL_Downsample_S16LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10118 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10119 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10120 fprintf(stderr, "Downsample (x4) AUDIO_S16LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10121 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10122
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10123 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10124 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10125 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10126 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10127 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10128 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10129 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10130 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10131 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10132 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10133 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10134 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10135 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10136 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10137 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10138 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10139 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10140 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10141 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10142 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10143 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10144 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10145 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10146 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10147 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10148
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10149 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10150 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10151 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10152 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10153 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10154
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10155 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10156 SDL_Upsample_S16LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10157 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10158 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10159 fprintf(stderr, "Upsample (x2) AUDIO_S16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10160 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10161
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10162 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10163 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10164 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10165 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10166 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10167 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10168 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10169 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10170 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10171 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10172 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10173 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10174 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10175 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10176 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10177 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10178 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10179 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10180 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10181 dst[11] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10182 dst[10] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10183 dst[9] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10184 dst[8] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10185 dst[7] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10186 dst[6] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10187 dst[5] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10188 dst[4] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10189 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10190 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10191 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10192 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10193 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10194 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10195 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10196 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10197 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10198 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10199 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10200 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10201
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10202 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10203 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10204 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10205 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10206 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10207
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10208 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10209 SDL_Downsample_S16LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10210 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10211 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10212 fprintf(stderr, "Downsample (x2) AUDIO_S16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10213 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10214
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10215 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10216 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10217 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10218 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10219 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10220 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10221 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10222 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10223 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10224 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10225 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10226 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10227 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10228 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10229 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10230 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10231 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10232 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10233 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10234 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10235 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10236 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10237 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10238 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10239 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10240 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10241 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10242 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10243 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10244 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10245 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10246 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10247 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10248
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10249 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10250 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10251 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10252 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10253 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10254
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10255 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10256 SDL_Upsample_S16LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10257 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10258 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10259 fprintf(stderr, "Upsample (x4) AUDIO_S16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10260 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10261
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10262 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10263 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10264 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10265 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10266 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10267 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10268 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10269 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10270 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10271 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10272 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10273 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10274 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10275 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10276 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10277 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10278 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10279 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10280 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10281 dst[23] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10282 dst[22] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10283 dst[21] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10284 dst[20] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10285 dst[19] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10286 dst[18] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10287 dst[17] = (Sint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10288 dst[16] = (Sint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10289 dst[15] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10290 dst[14] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10291 dst[13] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10292 dst[12] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10293 dst[11] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10294 dst[10] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10295 dst[9] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10296 dst[8] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10297 dst[7] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10298 dst[6] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10299 dst[5] = (Sint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10300 dst[4] = (Sint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10301 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10302 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10303 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10304 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10305 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10306 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10307 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10308 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10309 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10310 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10311 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10312 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10313
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10314 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10315 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10316 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10317 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10318 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10319
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10320 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10321 SDL_Downsample_S16LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10322 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10323 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10324 fprintf(stderr, "Downsample (x4) AUDIO_S16LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10325 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10326
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10327 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10328 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10329 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10330 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10331 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10332 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10333 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10334 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10335 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10336 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10337 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10338 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10339 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10340 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10341 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10342 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10343 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10344 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10345 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10346 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10347 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10348 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10349 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10350 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10351 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10352 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10353 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10354 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10355 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10356 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10357 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10358 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10359 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10360
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10361 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10362 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10363 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10364 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10365 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10366
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10367 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10368 SDL_Upsample_S16LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10369 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10370 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10371 fprintf(stderr, "Upsample (x2) AUDIO_S16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10372 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10373
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10374 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10375 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10376 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10377 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10378 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10379 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10380 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10381 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10382 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10383 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10384 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10385 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10386 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10387 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10388 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10389 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10390 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10391 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10392 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10393 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10394 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10395 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10396 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10397 dst[15] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10398 dst[14] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10399 dst[13] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10400 dst[12] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10401 dst[11] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10402 dst[10] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10403 dst[9] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10404 dst[8] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10405 dst[7] = (Sint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10406 dst[6] = (Sint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10407 dst[5] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10408 dst[4] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10409 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10410 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10411 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10412 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10413 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10414 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10415 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10416 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10417 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10418 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10419 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10420 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10421 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10422 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10423
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10424 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10425 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10426 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10427 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10428 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10429
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10430 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10431 SDL_Downsample_S16LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10432 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10433 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10434 fprintf(stderr, "Downsample (x2) AUDIO_S16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10435 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10436
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10437 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10438 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10439 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10440 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10441 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10442 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10443 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10444 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10445 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10446 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10447 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10448 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10449 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10450 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10451 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10452 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10453 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10454 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10455 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10456 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10457 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10458 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10459 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10460 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10461 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10462 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10463 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10464 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10465 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10466 dst[6] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10467 dst[7] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10468 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10469 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10470 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10471 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10472 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10473 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10474 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10475 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10476 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10477 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10478
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10479 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10480 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10481 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10482 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10483 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10484
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10485 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10486 SDL_Upsample_S16LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10487 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10488 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10489 fprintf(stderr, "Upsample (x4) AUDIO_S16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10490 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10491
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10492 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10493 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10494 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10495 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10496 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10497 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10498 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10499 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10500 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10501 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10502 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10503 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10504 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10505 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10506 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10507 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10508 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10509 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10510 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10511 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10512 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10513 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10514 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10515 dst[31] = (Sint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10516 dst[30] = (Sint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10517 dst[29] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10518 dst[28] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10519 dst[27] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10520 dst[26] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10521 dst[25] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10522 dst[24] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10523 dst[23] = (Sint16) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10524 dst[22] = (Sint16) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10525 dst[21] = (Sint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10526 dst[20] = (Sint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10527 dst[19] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10528 dst[18] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10529 dst[17] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10530 dst[16] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10531 dst[15] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10532 dst[14] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10533 dst[13] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10534 dst[12] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10535 dst[11] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10536 dst[10] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10537 dst[9] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10538 dst[8] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10539 dst[7] = (Sint16) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10540 dst[6] = (Sint16) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10541 dst[5] = (Sint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10542 dst[4] = (Sint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10543 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10544 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10545 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10546 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10547 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10548 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10549 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10550 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10551 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10552 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10553 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10554 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10555 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10556 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10557
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10558 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10559 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10560 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10561 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10562 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10563
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10564 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10565 SDL_Downsample_S16LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10566 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10567 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10568 fprintf(stderr, "Downsample (x4) AUDIO_S16LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10569 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10570
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10571 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10572 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10573 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10574 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10575 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10576 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10577 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10578 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10579 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10580 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10581 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10582 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10583 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10584 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10585 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapLE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10586 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapLE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10587 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapLE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10588 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapLE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10589 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapLE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10590 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapLE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10591 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapLE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10592 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapLE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10593 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10594 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10595 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10596 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10597 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10598 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10599 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10600 dst[6] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10601 dst[7] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10602 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10603 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10604 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10605 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10606 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10607 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10608 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10609 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10610 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10611 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10612
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10613 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10614 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10615 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10616 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10617 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10618
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10619 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10620 SDL_Upsample_U16MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10621 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10622 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10623 fprintf(stderr, "Upsample (x2) AUDIO_U16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10624 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10625
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10626 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10627 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10628 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10629 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10630 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10631 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10632 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10633 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10634 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10635 dst[1] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10636 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10637 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10638 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10639 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10640
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10641 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10642 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10643 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10644 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10645 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10646
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10647 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10648 SDL_Downsample_U16MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10649 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10650 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10651 fprintf(stderr, "Downsample (x2) AUDIO_U16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10652 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10653
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10654 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10655 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10656 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10657 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10658 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10659 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10660 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10661 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10662 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10663 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10664 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10665 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10666 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10667
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10668 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10669 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10670 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10671 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10672 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10673
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10674 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10675 SDL_Upsample_U16MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10676 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10677 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10678 fprintf(stderr, "Upsample (x4) AUDIO_U16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10679 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10680
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10681 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10682 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10683 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10684 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10685 const Uint16 *target = ((const Uint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10686 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10687 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10688 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10689 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10690 dst[3] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10691 dst[2] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10692 dst[1] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10693 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10694 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10695 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10696 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10697
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10698 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10699 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10700 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10701 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10702 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10703
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10704 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10705 SDL_Downsample_U16MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10706 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10707 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10708 fprintf(stderr, "Downsample (x4) AUDIO_U16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10709 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10710
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10711 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10712 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10713 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10714 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10715 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10716 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10717 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10718 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10719 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10720 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10721 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10722 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10723 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10724
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10725 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10726 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10727 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10728 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10729 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10730
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10731 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10732 SDL_Upsample_U16MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10733 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10734 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10735 fprintf(stderr, "Upsample (x2) AUDIO_U16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10736 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10737
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10738 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10739 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10740 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10741 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10742 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10743 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10744 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10745 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10746 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10747 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10748 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10749 dst[3] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10750 dst[2] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10751 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10752 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10753 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10754 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10755 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10756 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10757
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10758 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10759 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10760 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10761 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10762 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10763
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10764 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10765 SDL_Downsample_U16MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10766 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10767 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10768 fprintf(stderr, "Downsample (x2) AUDIO_U16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10769 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10770
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10771 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10772 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10773 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10774 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10775 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10776 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10777 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10778 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10779 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10780 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10781 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10782 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10783 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10784 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10785 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10786 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10787 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10788
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10789 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10790 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10791 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10792 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10793 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10794
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10795 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10796 SDL_Upsample_U16MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10797 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10798 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10799 fprintf(stderr, "Upsample (x4) AUDIO_U16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10800 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10801
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10802 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10803 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10804 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10805 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10806 const Uint16 *target = ((const Uint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10807 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10808 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10809 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10810 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10811 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10812 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10813 dst[7] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10814 dst[6] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10815 dst[5] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10816 dst[4] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10817 dst[3] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10818 dst[2] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10819 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10820 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10821 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10822 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10823 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10824 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10825
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10826 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10827 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10828 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10829 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10830 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10831
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10832 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10833 SDL_Downsample_U16MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10834 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10835 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10836 fprintf(stderr, "Downsample (x4) AUDIO_U16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10837 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10838
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10839 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10840 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10841 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10842 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10843 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10844 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10845 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10846 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10847 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10848 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10849 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10850 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10851 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10852 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10853 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10854 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10855 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10856
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10857 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10858 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10859 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10860 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10861 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10862
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10863 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10864 SDL_Upsample_U16MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10865 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10866 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10867 fprintf(stderr, "Upsample (x2) AUDIO_U16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10868 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10869
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10870 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10871 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10872 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10873 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10874 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10875 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10876 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10877 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10878 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10879 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10880 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10881 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10882 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10883 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10884 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10885 dst[7] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10886 dst[6] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10887 dst[5] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10888 dst[4] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10889 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10890 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10891 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10892 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10893 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10894 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10895 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10896 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10897 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10898 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10899
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10900 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10901 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10902 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10903 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10904 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10905
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10906 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10907 SDL_Downsample_U16MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10908 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10909 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10910 fprintf(stderr, "Downsample (x2) AUDIO_U16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10911 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10912
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10913 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10914 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10915 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10916 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10917 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10918 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10919 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10920 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10921 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10922 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10923 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10924 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10925 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10926 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10927 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10928 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10929 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10930 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10931 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10932 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10933 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10934 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10935 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10936 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10937 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10938
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10939 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10940 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10941 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10942 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10943 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10944
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10945 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10946 SDL_Upsample_U16MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10947 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10948 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10949 fprintf(stderr, "Upsample (x4) AUDIO_U16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10950 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10951
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10952 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10953 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10954 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10955 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10956 const Uint16 *target = ((const Uint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10957 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10958 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10959 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10960 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
10961 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10962 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10963 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10964 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10965 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10966 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10967 dst[15] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10968 dst[14] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10969 dst[13] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10970 dst[12] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10971 dst[11] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10972 dst[10] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10973 dst[9] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10974 dst[8] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10975 dst[7] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10976 dst[6] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10977 dst[5] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10978 dst[4] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10979 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10980 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10981 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10982 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10983 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10984 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10985 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10986 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10987 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10988 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10989
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10990 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10991 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10992 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10993 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10994 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10995
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10996 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10997 SDL_Downsample_U16MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
10998 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
10999 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11000 fprintf(stderr, "Downsample (x4) AUDIO_U16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11001 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11002
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11003 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11004 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11005 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11006 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11007 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11008 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11009 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11010 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11011 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11012 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11013 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11014 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11015 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11016 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11017 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11018 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11019 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11020 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11021 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11022 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11023 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11024 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11025 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11026 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11027 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11028
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11029 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11030 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11031 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11032 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11033 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11034
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11035 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11036 SDL_Upsample_U16MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11037 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11038 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11039 fprintf(stderr, "Upsample (x2) AUDIO_U16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11040 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11041
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11042 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11043 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11044 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11045 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11046 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11047 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11048 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11049 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11050 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11051 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11052 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11053 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11054 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11055 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11056 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11057 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11058 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11059 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11060 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11061 dst[11] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11062 dst[10] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11063 dst[9] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11064 dst[8] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11065 dst[7] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11066 dst[6] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11067 dst[5] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11068 dst[4] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11069 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11070 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11071 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11072 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11073 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11074 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11075 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11076 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11077 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11078 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11079 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11080 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11081
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11082 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11083 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11084 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11085 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11086 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11087
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11088 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11089 SDL_Downsample_U16MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11090 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11091 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11092 fprintf(stderr, "Downsample (x2) AUDIO_U16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11093 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11094
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11095 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11096 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11097 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11098 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11099 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11100 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11101 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11102 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11103 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11104 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11105 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11106 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11107 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11108 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11109 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11110 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11111 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11112 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11113 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11114 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11115 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11116 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11117 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11118 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11119 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11120 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11121 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11122 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11123 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11124 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11125 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11126 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11127 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11128
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11129 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11130 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11131 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11132 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11133 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11134
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11135 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11136 SDL_Upsample_U16MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11137 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11138 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11139 fprintf(stderr, "Upsample (x4) AUDIO_U16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11140 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11141
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11142 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11143 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11144 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11145 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11146 const Uint16 *target = ((const Uint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11147 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11148 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11149 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11150 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11151 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11152 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11153 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11154 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11155 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11156 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11157 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11158 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11159 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11160 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11161 dst[23] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11162 dst[22] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11163 dst[21] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11164 dst[20] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11165 dst[19] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11166 dst[18] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11167 dst[17] = (Uint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11168 dst[16] = (Uint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11169 dst[15] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11170 dst[14] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11171 dst[13] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11172 dst[12] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11173 dst[11] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11174 dst[10] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11175 dst[9] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11176 dst[8] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11177 dst[7] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11178 dst[6] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11179 dst[5] = (Uint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11180 dst[4] = (Uint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11181 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11182 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11183 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11184 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11185 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11186 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11187 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11188 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11189 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11190 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11191 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11192 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11193
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11194 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11195 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11196 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11197 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11198 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11199
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11200 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11201 SDL_Downsample_U16MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11202 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11203 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11204 fprintf(stderr, "Downsample (x4) AUDIO_U16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11205 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11206
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11207 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11208 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11209 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11210 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11211 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11212 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11213 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11214 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11215 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11216 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11217 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11218 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11219 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11220 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11221 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11222 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11223 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11224 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11225 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11226 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11227 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11228 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11229 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11230 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11231 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11232 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11233 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11234 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11235 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11236 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11237 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11238 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11239 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11240
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11241 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11242 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11243 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11244 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11245 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11246
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11247 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11248 SDL_Upsample_U16MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11249 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11250 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11251 fprintf(stderr, "Upsample (x2) AUDIO_U16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11252 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11253
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11254 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11255 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11256 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11257 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11258 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11259 Sint32 last_sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11260 Sint32 last_sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11261 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11262 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11263 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11264 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11265 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11266 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11267 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11268 const Sint32 sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11269 const Sint32 sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11270 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11271 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11272 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11273 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11274 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11275 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11276 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11277 dst[15] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11278 dst[14] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11279 dst[13] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11280 dst[12] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11281 dst[11] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11282 dst[10] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11283 dst[9] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11284 dst[8] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11285 dst[7] = (Uint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11286 dst[6] = (Uint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11287 dst[5] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11288 dst[4] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11289 dst[3] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11290 dst[2] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11291 dst[1] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11292 dst[0] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11293 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11294 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11295 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11296 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11297 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11298 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11299 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11300 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11301 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11302 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11303
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11304 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11305 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11306 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11307 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11308 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11309
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11310 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11311 SDL_Downsample_U16MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11312 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11313 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11314 fprintf(stderr, "Downsample (x2) AUDIO_U16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11315 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11316
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11317 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11318 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11319 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11320 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11321 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11322 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11323 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11324 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11325 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11326 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11327 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11328 Sint32 last_sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11329 Sint32 last_sample7 = (Sint32) SDL_SwapBE16(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11330 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11331 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11332 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11333 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11334 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11335 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11336 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11337 const Sint32 sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11338 const Sint32 sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11339 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11340 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11341 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11342 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11343 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11344 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11345 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11346 dst[6] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11347 dst[7] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11348 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11349 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11350 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11351 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11352 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11353 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11354 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11355 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11356 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11357 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11358
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11359 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11360 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11361 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11362 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11363 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11364
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11365 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11366 SDL_Upsample_U16MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11367 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11368 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11369 fprintf(stderr, "Upsample (x4) AUDIO_U16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11370 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11371
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11372 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11373 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11374 Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11375 const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11376 const Uint16 *target = ((const Uint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11377 Sint32 last_sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11378 Sint32 last_sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11379 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11380 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11381 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11382 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11383 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11384 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11385 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11386 const Sint32 sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11387 const Sint32 sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11388 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11389 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11390 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11391 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11392 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11393 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11394 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11395 dst[31] = (Uint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11396 dst[30] = (Uint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11397 dst[29] = (Uint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11398 dst[28] = (Uint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11399 dst[27] = (Uint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11400 dst[26] = (Uint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11401 dst[25] = (Uint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11402 dst[24] = (Uint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11403 dst[23] = (Uint16) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11404 dst[22] = (Uint16) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11405 dst[21] = (Uint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11406 dst[20] = (Uint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11407 dst[19] = (Uint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11408 dst[18] = (Uint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11409 dst[17] = (Uint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11410 dst[16] = (Uint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11411 dst[15] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11412 dst[14] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11413 dst[13] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11414 dst[12] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11415 dst[11] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11416 dst[10] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11417 dst[9] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11418 dst[8] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11419 dst[7] = (Uint16) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11420 dst[6] = (Uint16) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11421 dst[5] = (Uint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11422 dst[4] = (Uint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11423 dst[3] = (Uint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11424 dst[2] = (Uint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11425 dst[1] = (Uint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11426 dst[0] = (Uint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11427 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11428 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11429 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11430 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11431 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11432 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11433 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11434 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11435 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11436 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11437
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11438 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11439 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11440 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11441 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11442 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11443
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11444 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11445 SDL_Downsample_U16MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11446 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11447 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11448 fprintf(stderr, "Downsample (x4) AUDIO_U16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11449 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11450
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11451 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11452 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11453 Uint16 *dst = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11454 const Uint16 *src = (Uint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11455 const Uint16 *target = (const Uint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11456 Sint32 last_sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11457 Sint32 last_sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11458 Sint32 last_sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11459 Sint32 last_sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11460 Sint32 last_sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11461 Sint32 last_sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11462 Sint32 last_sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11463 Sint32 last_sample7 = (Sint32) SDL_SwapBE16(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11464 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11465 const Sint32 sample0 = (Sint32) SDL_SwapBE16(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11466 const Sint32 sample1 = (Sint32) SDL_SwapBE16(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11467 const Sint32 sample2 = (Sint32) SDL_SwapBE16(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11468 const Sint32 sample3 = (Sint32) SDL_SwapBE16(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11469 const Sint32 sample4 = (Sint32) SDL_SwapBE16(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11470 const Sint32 sample5 = (Sint32) SDL_SwapBE16(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11471 const Sint32 sample6 = (Sint32) SDL_SwapBE16(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11472 const Sint32 sample7 = (Sint32) SDL_SwapBE16(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11473 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11474 dst[0] = (Uint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11475 dst[1] = (Uint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11476 dst[2] = (Uint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11477 dst[3] = (Uint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11478 dst[4] = (Uint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11479 dst[5] = (Uint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11480 dst[6] = (Uint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11481 dst[7] = (Uint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11482 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11483 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11484 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11485 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11486 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11487 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11488 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11489 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11490 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11491 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11492
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11493 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11494 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11495 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11496 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11497 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11498
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11499 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11500 SDL_Upsample_S16MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11501 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11502 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11503 fprintf(stderr, "Upsample (x2) AUDIO_S16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11504 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11505
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11506 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11507 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11508 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11509 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11510 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11511 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11512 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11513 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11514 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11515 dst[1] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11516 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11517 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11518 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11519 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11520
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11521 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11522 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11523 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11524 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11525 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11526
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11527 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11528 SDL_Downsample_S16MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11529 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11530 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11531 fprintf(stderr, "Downsample (x2) AUDIO_S16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11532 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11533
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11534 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11535 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11536 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11537 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11538 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11539 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11540 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11541 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11542 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11543 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11544 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11545 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11546 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11547
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11548 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11549 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11550 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11551 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11552 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11553
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11554 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11555 SDL_Upsample_S16MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11556 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11557 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11558 fprintf(stderr, "Upsample (x4) AUDIO_S16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11559 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11560
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11561 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11562 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11563 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11564 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11565 const Sint16 *target = ((const Sint16 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11566 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11567 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11568 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11569 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11570 dst[3] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11571 dst[2] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11572 dst[1] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11573 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11574 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11575 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11576 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11577
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11578 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11579 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11580 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11581 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11582 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11583
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11584 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11585 SDL_Downsample_S16MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11586 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11587 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11588 fprintf(stderr, "Downsample (x4) AUDIO_S16MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11589 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11590
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11591 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11592 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11593 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11594 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11595 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11596 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11597 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11598 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11599 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11600 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11601 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11602 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11603 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11604
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11605 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11606 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11607 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11608 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11609 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11610
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11611 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11612 SDL_Upsample_S16MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11613 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11614 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11615 fprintf(stderr, "Upsample (x2) AUDIO_S16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11616 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11617
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11618 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11619 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11620 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11621 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11622 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11623 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11624 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11625 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11626 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11627 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11628 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11629 dst[3] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11630 dst[2] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11631 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11632 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11633 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11634 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11635 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11636 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11637
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11638 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11639 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11640 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11641 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11642 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11643
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11644 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11645 SDL_Downsample_S16MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11646 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11647 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11648 fprintf(stderr, "Downsample (x2) AUDIO_S16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11649 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11650
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11651 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11652 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11653 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11654 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11655 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11656 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11657 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11658 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11659 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11660 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11661 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11662 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11663 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11664 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11665 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11666 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11667 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11668
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11669 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11670 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11671 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11672 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11673 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11674
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11675 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11676 SDL_Upsample_S16MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11677 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11678 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11679 fprintf(stderr, "Upsample (x4) AUDIO_S16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11680 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11681
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11682 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11683 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11684 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11685 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11686 const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11687 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11688 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11689 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11690 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11691 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11692 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11693 dst[7] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11694 dst[6] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11695 dst[5] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11696 dst[4] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11697 dst[3] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11698 dst[2] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11699 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11700 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11701 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11702 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11703 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11704 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11705
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11706 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11707 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11708 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11709 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11710 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11711
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11712 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11713 SDL_Downsample_S16MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11714 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11715 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11716 fprintf(stderr, "Downsample (x4) AUDIO_S16MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11717 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11718
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11719 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11720 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11721 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11722 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11723 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11724 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11725 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11726 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11727 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11728 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11729 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11730 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11731 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11732 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11733 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11734 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11735 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11736
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11737 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11738 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11739 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11740 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11741 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11742
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11743 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11744 SDL_Upsample_S16MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11745 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11746 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11747 fprintf(stderr, "Upsample (x2) AUDIO_S16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11748 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11749
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11750 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11751 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11752 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11753 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11754 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11755 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11756 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11757 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11758 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11759 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11760 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11761 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11762 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11763 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11764 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11765 dst[7] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11766 dst[6] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11767 dst[5] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11768 dst[4] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11769 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11770 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11771 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11772 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11773 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11774 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11775 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11776 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11777 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11778 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11779
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11780 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11781 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11782 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11783 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11784 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11785
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11786 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11787 SDL_Downsample_S16MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11788 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11789 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11790 fprintf(stderr, "Downsample (x2) AUDIO_S16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11791 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11792
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11793 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11794 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11795 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11796 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11797 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11798 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11799 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11800 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11801 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11802 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11803 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11804 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11805 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11806 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11807 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11808 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11809 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11810 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11811 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11812 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11813 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11814 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11815 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11816 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11817 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11818
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11819 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11820 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11821 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11822 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11823 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11824
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11825 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11826 SDL_Upsample_S16MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11827 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11828 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11829 fprintf(stderr, "Upsample (x4) AUDIO_S16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11830 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11831
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11832 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11833 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11834 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11835 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11836 const Sint16 *target = ((const Sint16 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11837 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11838 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11839 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11840 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11841 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11842 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11843 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11844 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11845 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11846 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11847 dst[15] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11848 dst[14] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11849 dst[13] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11850 dst[12] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11851 dst[11] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11852 dst[10] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11853 dst[9] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11854 dst[8] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11855 dst[7] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11856 dst[6] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11857 dst[5] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11858 dst[4] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11859 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11860 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11861 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11862 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11863 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11864 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11865 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11866 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11867 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11868 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11869
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11870 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11871 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11872 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11873 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11874 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11875
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11876 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11877 SDL_Downsample_S16MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11878 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11879 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11880 fprintf(stderr, "Downsample (x4) AUDIO_S16MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11881 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11882
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11883 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11884 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11885 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11886 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11887 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11888 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11889 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11890 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11891 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11892 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11893 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11894 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11895 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11896 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11897 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11898 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11899 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11900 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11901 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11902 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11903 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11904 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11905 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11906 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11907 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11908
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11909 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11910 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11911 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11912 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11913 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11914
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11915 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11916 SDL_Upsample_S16MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11917 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11918 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11919 fprintf(stderr, "Upsample (x2) AUDIO_S16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11920 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11921
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11922 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11923 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11924 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11925 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11926 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11927 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11928 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11929 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11930 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11931 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11932 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11933 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11934 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11935 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11936 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11937 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11938 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11939 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11940 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11941 dst[11] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11942 dst[10] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11943 dst[9] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11944 dst[8] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11945 dst[7] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11946 dst[6] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11947 dst[5] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11948 dst[4] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11949 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11950 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11951 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11952 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11953 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11954 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11955 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11956 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11957 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11958 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11959 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11960 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11961
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11962 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11963 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11964 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11965 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11966 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11967
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11968 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11969 SDL_Downsample_S16MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11970 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
11971 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11972 fprintf(stderr, "Downsample (x2) AUDIO_S16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11973 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11974
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11975 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11976 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11977 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11978 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11979 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11980 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11981 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11982 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11983 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11984 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11985 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
11986 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11987 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11988 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11989 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11990 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11991 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11992 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11993 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11994 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11995 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11996 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11997 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11998 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
11999 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12000 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12001 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12002 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12003 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12004 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12005 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12006 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12007 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12008
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12009 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12010 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12011 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12012 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12013 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12014
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12015 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12016 SDL_Upsample_S16MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12017 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12018 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12019 fprintf(stderr, "Upsample (x4) AUDIO_S16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12020 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12022 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12023 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12024 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12025 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12026 const Sint16 *target = ((const Sint16 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12027 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12028 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12029 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12030 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12031 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12032 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12033 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12034 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12035 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12036 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12037 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12038 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12039 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12040 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12041 dst[23] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12042 dst[22] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12043 dst[21] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12044 dst[20] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12045 dst[19] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12046 dst[18] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12047 dst[17] = (Sint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12048 dst[16] = (Sint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12049 dst[15] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12050 dst[14] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12051 dst[13] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12052 dst[12] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12053 dst[11] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12054 dst[10] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12055 dst[9] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12056 dst[8] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12057 dst[7] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12058 dst[6] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12059 dst[5] = (Sint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12060 dst[4] = (Sint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12061 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12062 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12063 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12064 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12065 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12066 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12067 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12068 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12069 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12070 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12071 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12072 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12073
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12074 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12075 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12076 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12077 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12078 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12079
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12080 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12081 SDL_Downsample_S16MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12082 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12083 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12084 fprintf(stderr, "Downsample (x4) AUDIO_S16MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12085 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12086
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12087 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12088 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12089 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12090 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12091 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12092 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12093 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12094 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12095 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12096 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12097 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12098 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12099 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12100 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12101 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12102 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12103 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12104 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12105 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12106 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12107 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12108 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12109 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12110 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12111 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12112 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12113 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12114 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12115 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12116 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12117 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12118 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12119 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12120
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12121 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12122 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12123 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12124 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12125 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12126
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12127 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12128 SDL_Upsample_S16MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12129 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12130 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12131 fprintf(stderr, "Upsample (x2) AUDIO_S16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12132 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12133
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12134 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12135 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12136 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12137 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12138 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12139 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12140 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12141 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12142 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12143 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12144 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12145 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12146 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12147 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12148 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12149 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12150 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12151 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12152 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12153 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12154 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12155 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12156 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12157 dst[15] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12158 dst[14] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12159 dst[13] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12160 dst[12] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12161 dst[11] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12162 dst[10] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12163 dst[9] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12164 dst[8] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12165 dst[7] = (Sint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12166 dst[6] = (Sint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12167 dst[5] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12168 dst[4] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12169 dst[3] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12170 dst[2] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12171 dst[1] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12172 dst[0] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12173 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12174 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12175 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12176 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12177 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12178 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12179 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12180 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12181 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12182 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12183
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12184 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12185 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12186 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12187 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12188 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12189
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12190 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12191 SDL_Downsample_S16MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12192 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12193 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12194 fprintf(stderr, "Downsample (x2) AUDIO_S16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12195 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12196
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12197 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12198 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12199 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12200 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12201 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12202 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12203 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12204 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12205 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12206 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12207 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12208 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12209 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12210 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12211 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12212 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12213 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12214 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12215 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12216 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12217 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12218 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12219 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12220 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12221 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12222 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12223 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12224 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12225 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12226 dst[6] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12227 dst[7] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12228 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12229 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12230 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12231 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12232 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12233 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12234 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12235 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12236 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12237 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12238
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12239 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12240 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12241 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12242 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12243 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12244
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12245 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12246 SDL_Upsample_S16MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12247 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12248 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12249 fprintf(stderr, "Upsample (x4) AUDIO_S16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12250 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12251
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12252 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12253 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12254 Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12255 const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12256 const Sint16 *target = ((const Sint16 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12257 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12258 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12259 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12260 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12261 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12262 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12263 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12264 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12265 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12266 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12267 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12268 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12269 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12270 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12271 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12272 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12273 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12274 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12275 dst[31] = (Sint16) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12276 dst[30] = (Sint16) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12277 dst[29] = (Sint16) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12278 dst[28] = (Sint16) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12279 dst[27] = (Sint16) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12280 dst[26] = (Sint16) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12281 dst[25] = (Sint16) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12282 dst[24] = (Sint16) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12283 dst[23] = (Sint16) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12284 dst[22] = (Sint16) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12285 dst[21] = (Sint16) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12286 dst[20] = (Sint16) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12287 dst[19] = (Sint16) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12288 dst[18] = (Sint16) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12289 dst[17] = (Sint16) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12290 dst[16] = (Sint16) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12291 dst[15] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12292 dst[14] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12293 dst[13] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12294 dst[12] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12295 dst[11] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12296 dst[10] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12297 dst[9] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12298 dst[8] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12299 dst[7] = (Sint16) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12300 dst[6] = (Sint16) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12301 dst[5] = (Sint16) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12302 dst[4] = (Sint16) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12303 dst[3] = (Sint16) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12304 dst[2] = (Sint16) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12305 dst[1] = (Sint16) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12306 dst[0] = (Sint16) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12307 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12308 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12309 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12310 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12311 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12312 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12313 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12314 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12315 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12316 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12317
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12318 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12319 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12320 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12321 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12322 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12323
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12324 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12325 SDL_Downsample_S16MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12326 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12327 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12328 fprintf(stderr, "Downsample (x4) AUDIO_S16MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12329 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12330
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12331 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12332 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12333 Sint16 *dst = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12334 const Sint16 *src = (Sint16 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12335 const Sint16 *target = (const Sint16 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12336 Sint32 last_sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12337 Sint32 last_sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12338 Sint32 last_sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12339 Sint32 last_sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12340 Sint32 last_sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12341 Sint32 last_sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12342 Sint32 last_sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12343 Sint32 last_sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12344 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12345 const Sint32 sample0 = (Sint32) ((Sint16) SDL_SwapBE16(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12346 const Sint32 sample1 = (Sint32) ((Sint16) SDL_SwapBE16(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12347 const Sint32 sample2 = (Sint32) ((Sint16) SDL_SwapBE16(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12348 const Sint32 sample3 = (Sint32) ((Sint16) SDL_SwapBE16(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12349 const Sint32 sample4 = (Sint32) ((Sint16) SDL_SwapBE16(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12350 const Sint32 sample5 = (Sint32) ((Sint16) SDL_SwapBE16(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12351 const Sint32 sample6 = (Sint32) ((Sint16) SDL_SwapBE16(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12352 const Sint32 sample7 = (Sint32) ((Sint16) SDL_SwapBE16(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12353 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12354 dst[0] = (Sint16) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12355 dst[1] = (Sint16) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12356 dst[2] = (Sint16) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12357 dst[3] = (Sint16) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12358 dst[4] = (Sint16) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12359 dst[5] = (Sint16) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12360 dst[6] = (Sint16) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12361 dst[7] = (Sint16) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12362 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12363 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12364 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12365 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12366 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12367 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12368 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12369 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12370 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12371 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12372
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12373 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12374 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12375 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12376 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12377 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12378
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12379 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12380 SDL_Upsample_S32LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12381 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12382 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12383 fprintf(stderr, "Upsample (x2) AUDIO_S32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12384 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12385
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12386 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12387 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12388 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12389 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12390 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12391 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12392 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12393 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12394 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12395 dst[1] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12396 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12397 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12398 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12399 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12400
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12401 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12402 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12403 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12404 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12405 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12406
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12407 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12408 SDL_Downsample_S32LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12409 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12410 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12411 fprintf(stderr, "Downsample (x2) AUDIO_S32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12412 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12413
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12414 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12415 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12416 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12417 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12418 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12419 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12420 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12421 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12422 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12423 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12424 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12425 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12426 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12427
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12428 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12429 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12430 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12431 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12432 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12433
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12434 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12435 SDL_Upsample_S32LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12436 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12437 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12438 fprintf(stderr, "Upsample (x4) AUDIO_S32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12439 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12440
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12441 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12442 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12443 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12444 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12445 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12446 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12447 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12448 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12449 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12450 dst[3] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12451 dst[2] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12452 dst[1] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12453 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12454 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12455 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12456 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12457
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12458 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12459 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12460 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12461 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12462 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12463
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12464 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12465 SDL_Downsample_S32LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12466 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12467 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12468 fprintf(stderr, "Downsample (x4) AUDIO_S32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12469 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12470
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12471 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12472 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12473 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12474 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12475 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12476 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12477 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12478 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12479 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12480 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12481 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12482 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12483 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12484
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12485 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12486 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12487 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12488 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12489 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12490
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12491 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12492 SDL_Upsample_S32LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12493 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12494 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12495 fprintf(stderr, "Upsample (x2) AUDIO_S32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12496 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12497
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12498 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12499 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12500 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12501 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12502 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12503 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12504 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12505 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12506 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12507 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12508 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12509 dst[3] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12510 dst[2] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12511 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12512 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12513 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12514 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12515 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12516 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12517
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12518 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12519 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12520 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12521 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12522 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12523
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12524 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12525 SDL_Downsample_S32LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12526 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12527 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12528 fprintf(stderr, "Downsample (x2) AUDIO_S32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12529 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12530
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12531 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12532 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12533 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12534 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12535 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12536 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12537 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12538 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12539 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12540 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12541 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12542 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12543 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12544 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12545 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12546 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12547 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12548
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12549 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12550 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12551 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12552 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12553 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12554
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12555 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12556 SDL_Upsample_S32LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12557 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12558 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12559 fprintf(stderr, "Upsample (x4) AUDIO_S32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12560 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12561
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12562 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12563 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12564 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12565 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12566 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12567 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12568 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12569 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12570 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12571 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12572 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12573 dst[7] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12574 dst[6] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12575 dst[5] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12576 dst[4] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12577 dst[3] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12578 dst[2] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12579 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12580 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12581 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12582 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12583 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12584 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12585
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12586 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12587 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12588 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12589 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12590 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12591
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12592 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12593 SDL_Downsample_S32LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12594 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12595 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12596 fprintf(stderr, "Downsample (x4) AUDIO_S32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12597 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12598
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12599 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12600 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12601 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12602 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12603 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12604 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12605 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12606 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12607 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12608 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12609 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12610 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12611 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12612 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12613 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12614 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12615 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12616
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12617 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12618 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12619 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12620 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12621 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12622
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12623 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12624 SDL_Upsample_S32LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12625 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12626 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12627 fprintf(stderr, "Upsample (x2) AUDIO_S32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12628 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12629
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12630 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12631 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12632 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12633 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12634 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12635 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12636 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12637 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12638 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12639 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12640 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12641 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12642 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12643 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12644 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12645 dst[7] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12646 dst[6] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12647 dst[5] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12648 dst[4] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12649 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12650 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12651 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12652 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12653 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12654 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12655 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12656 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12657 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12658 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12659
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12660 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12661 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12662 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12663 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12664 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12665
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12666 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12667 SDL_Downsample_S32LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12668 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12669 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12670 fprintf(stderr, "Downsample (x2) AUDIO_S32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12671 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12672
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12673 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12674 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12675 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12676 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12677 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12678 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12679 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12680 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12681 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12682 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12683 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12684 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12685 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12686 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12687 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12688 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12689 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12690 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12691 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12692 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12693 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12694 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12695 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12696 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12697 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12698
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12699 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12700 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12701 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12702 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12703 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12704
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12705 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12706 SDL_Upsample_S32LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12707 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12708 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12709 fprintf(stderr, "Upsample (x4) AUDIO_S32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12710 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12711
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12712 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12713 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12714 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12715 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12716 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12717 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12718 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12719 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12720 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12721 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12722 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12723 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12724 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12725 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12726 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12727 dst[15] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12728 dst[14] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12729 dst[13] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12730 dst[12] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12731 dst[11] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12732 dst[10] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12733 dst[9] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12734 dst[8] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12735 dst[7] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12736 dst[6] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12737 dst[5] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12738 dst[4] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12739 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12740 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12741 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12742 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12743 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12744 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12745 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12746 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12747 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12748 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12749
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12750 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12751 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12752 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12753 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12754 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12755
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12756 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12757 SDL_Downsample_S32LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12758 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12759 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12760 fprintf(stderr, "Downsample (x4) AUDIO_S32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12761 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12762
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12763 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12764 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12765 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12766 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12767 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12768 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12769 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12770 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12771 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12772 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12773 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12774 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12775 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12776 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12777 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12778 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12779 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12780 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12781 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12782 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12783 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12784 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12785 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12786 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12787 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12788
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12789 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12790 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12791 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12792 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12793 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12794
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12795 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12796 SDL_Upsample_S32LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12797 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12798 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12799 fprintf(stderr, "Upsample (x2) AUDIO_S32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12800 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12801
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12802 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12803 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12804 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12805 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12806 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12807 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12808 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12809 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12810 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12811 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12812 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12813 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12814 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12815 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12816 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12817 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12818 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12819 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12820 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12821 dst[11] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12822 dst[10] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12823 dst[9] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12824 dst[8] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12825 dst[7] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12826 dst[6] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12827 dst[5] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12828 dst[4] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12829 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12830 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12831 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12832 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12833 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12834 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12835 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12836 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12837 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12838 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12839 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12840 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12841
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12842 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12843 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12844 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12845 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12846 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12847
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12848 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12849 SDL_Downsample_S32LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12850 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12851 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12852 fprintf(stderr, "Downsample (x2) AUDIO_S32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12853 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12854
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12855 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12856 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12857 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12858 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12859 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12860 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12861 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12862 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12863 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12864 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12865 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12866 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12867 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12868 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12869 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12870 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12871 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12872 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12873 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12874 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12875 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12876 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12877 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12878 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12879 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12880 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12881 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12882 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12883 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12884 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12885 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12886 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12887 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12888
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12889 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12890 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12891 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12892 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12893 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12894
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12895 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12896 SDL_Upsample_S32LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12897 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12898 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12899 fprintf(stderr, "Upsample (x4) AUDIO_S32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12900 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12901
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12902 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12903 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12904 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12905 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12906 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12907 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12908 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12909 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12910 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12911 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12912 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12913 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12914 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12915 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12916 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12917 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12918 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12919 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12920 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12921 dst[23] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12922 dst[22] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12923 dst[21] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12924 dst[20] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12925 dst[19] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12926 dst[18] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12927 dst[17] = (Sint32) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12928 dst[16] = (Sint32) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12929 dst[15] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12930 dst[14] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12931 dst[13] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12932 dst[12] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12933 dst[11] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12934 dst[10] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12935 dst[9] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12936 dst[8] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12937 dst[7] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12938 dst[6] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12939 dst[5] = (Sint32) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12940 dst[4] = (Sint32) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12941 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12942 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12943 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12944 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12945 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12946 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12947 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12948 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12949 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12950 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12951 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12952 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12953
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12954 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12955 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12956 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12957 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12958 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12959
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12960 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12961 SDL_Downsample_S32LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12962 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
12963 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12964 fprintf(stderr, "Downsample (x4) AUDIO_S32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12965 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12966
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12967 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12968 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12969 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12970 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12971 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12972 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12973 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12974 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12975 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12976 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12977 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
12978 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12979 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12980 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12981 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12982 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12983 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12984 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12985 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12986 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12987 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12988 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12989 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12990 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12991 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12992 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12993 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12994 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12995 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12996 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12997 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12998 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
12999 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13000
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13001 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13002 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13003 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13004 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13005 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13006
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13007 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13008 SDL_Upsample_S32LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13009 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13010 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13011 fprintf(stderr, "Upsample (x2) AUDIO_S32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13012 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13013
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13014 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13015 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13016 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13017 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13018 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13019 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13020 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13021 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13022 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13023 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13024 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13025 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13026 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13027 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13028 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13029 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13030 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13031 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13032 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13033 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13034 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13035 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13036 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13037 dst[15] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13038 dst[14] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13039 dst[13] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13040 dst[12] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13041 dst[11] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13042 dst[10] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13043 dst[9] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13044 dst[8] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13045 dst[7] = (Sint32) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13046 dst[6] = (Sint32) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13047 dst[5] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13048 dst[4] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13049 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13050 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13051 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13052 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13053 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13054 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13055 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13056 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13057 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13058 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13059 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13060 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13061 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13062 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13063
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13064 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13065 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13066 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13067 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13068 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13069
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13070 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13071 SDL_Downsample_S32LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13072 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13073 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13074 fprintf(stderr, "Downsample (x2) AUDIO_S32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13075 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13076
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13077 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13078 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13079 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13080 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13081 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13082 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13083 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13084 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13085 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13086 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13087 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13088 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13089 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13090 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13091 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13092 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13093 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13094 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13095 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13096 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13097 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13098 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13099 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13100 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13101 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13102 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13103 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13104 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13105 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13106 dst[6] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13107 dst[7] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13108 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13109 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13110 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13111 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13112 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13113 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13114 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13115 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13116 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13117 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13118
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13119 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13120 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13121 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13122 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13123 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13124
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13125 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13126 SDL_Upsample_S32LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13127 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13128 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13129 fprintf(stderr, "Upsample (x4) AUDIO_S32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13130 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13131
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13132 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13133 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13134 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13135 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13136 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13137 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13138 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13139 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13140 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13141 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13142 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13143 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13144 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13145 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13146 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13147 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13148 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13149 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13150 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13151 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13152 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13153 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13154 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13155 dst[31] = (Sint32) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13156 dst[30] = (Sint32) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13157 dst[29] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13158 dst[28] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13159 dst[27] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13160 dst[26] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13161 dst[25] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13162 dst[24] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13163 dst[23] = (Sint32) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13164 dst[22] = (Sint32) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13165 dst[21] = (Sint32) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13166 dst[20] = (Sint32) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13167 dst[19] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13168 dst[18] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13169 dst[17] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13170 dst[16] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13171 dst[15] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13172 dst[14] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13173 dst[13] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13174 dst[12] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13175 dst[11] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13176 dst[10] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13177 dst[9] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13178 dst[8] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13179 dst[7] = (Sint32) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13180 dst[6] = (Sint32) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13181 dst[5] = (Sint32) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13182 dst[4] = (Sint32) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13183 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13184 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13185 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13186 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13187 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13188 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13189 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13190 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13191 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13192 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13193 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13194 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13195 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13196 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13197
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13198 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13199 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13200 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13201 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13202 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13203
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13204 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13205 SDL_Downsample_S32LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13206 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13207 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13208 fprintf(stderr, "Downsample (x4) AUDIO_S32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13209 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13210
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13211 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13212 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13213 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13214 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13215 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13216 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13217 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13218 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13219 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13220 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13221 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13222 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13223 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13224 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13225 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapLE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13226 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapLE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13227 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapLE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13228 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapLE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13229 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapLE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13230 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapLE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13231 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapLE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13232 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapLE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13233 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13234 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13235 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13236 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13237 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13238 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13239 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13240 dst[6] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13241 dst[7] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13242 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13243 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13244 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13245 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13246 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13247 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13248 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13249 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13250 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13251 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13252
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13253 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13254 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13255 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13256 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13257 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13258
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13259 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13260 SDL_Upsample_S32MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13261 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13262 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13263 fprintf(stderr, "Upsample (x2) AUDIO_S32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13264 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13265
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13266 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13267 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13268 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13269 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13270 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13271 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13272 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13273 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13274 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13275 dst[1] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13276 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13277 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13278 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13279 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13280
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13281 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13282 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13283 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13284 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13285 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13286
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13287 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13288 SDL_Downsample_S32MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13289 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13290 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13291 fprintf(stderr, "Downsample (x2) AUDIO_S32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13292 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13293
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13294 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13295 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13296 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13297 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13298 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13299 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13300 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13301 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13302 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13303 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13304 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13305 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13306 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13307
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13308 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13309 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13310 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13311 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13312 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13313
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13314 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13315 SDL_Upsample_S32MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13316 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13317 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13318 fprintf(stderr, "Upsample (x4) AUDIO_S32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13319 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13320
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13321 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13322 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13323 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13324 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13325 const Sint32 *target = ((const Sint32 *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13326 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13327 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13328 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13329 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13330 dst[3] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13331 dst[2] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13332 dst[1] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13333 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13334 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13335 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13336 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13337
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13338 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13339 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13340 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13341 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13342 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13343
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13344 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13345 SDL_Downsample_S32MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13346 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13347 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13348 fprintf(stderr, "Downsample (x4) AUDIO_S32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13349 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13350
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13351 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13352 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13353 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13354 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13355 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13356 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13357 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13358 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13359 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13360 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13361 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13362 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13363 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13364
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13365 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13366 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13367 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13368 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13369 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13370
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13371 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13372 SDL_Upsample_S32MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13373 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13374 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13375 fprintf(stderr, "Upsample (x2) AUDIO_S32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13376 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13377
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13378 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13379 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13380 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13381 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13382 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13383 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13384 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13385 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13386 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13387 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13388 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13389 dst[3] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13390 dst[2] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13391 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13392 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13393 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13394 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13395 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13396 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13397
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13398 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13399 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13400 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13401 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13402 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13403
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13404 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13405 SDL_Downsample_S32MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13406 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13407 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13408 fprintf(stderr, "Downsample (x2) AUDIO_S32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13409 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13410
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13411 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13412 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13413 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13414 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13415 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13416 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13417 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13418 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13419 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13420 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13421 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13422 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13423 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13424 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13425 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13426 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13427 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13428
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13429 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13430 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13431 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13432 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13433 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13434
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13435 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13436 SDL_Upsample_S32MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13437 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13438 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13439 fprintf(stderr, "Upsample (x4) AUDIO_S32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13440 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13441
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13442 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13443 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13444 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13445 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13446 const Sint32 *target = ((const Sint32 *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13447 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13448 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13449 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13450 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13451 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13452 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13453 dst[7] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13454 dst[6] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13455 dst[5] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13456 dst[4] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13457 dst[3] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13458 dst[2] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13459 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13460 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13461 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13462 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13463 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13464 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13465
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13466 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13467 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13468 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13469 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13470 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13471
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13472 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13473 SDL_Downsample_S32MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13474 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13475 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13476 fprintf(stderr, "Downsample (x4) AUDIO_S32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13477 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13478
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13479 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13480 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13481 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13482 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13483 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13484 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13485 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13486 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13487 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13488 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13489 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13490 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13491 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13492 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13493 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13494 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13495 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13496
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13497 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13498 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13499 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13500 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13501 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13502
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13503 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13504 SDL_Upsample_S32MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13505 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13506 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13507 fprintf(stderr, "Upsample (x2) AUDIO_S32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13508 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13509
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13510 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13511 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13512 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13513 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13514 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13515 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13516 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13517 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13518 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13519 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13520 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13521 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13522 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13523 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13524 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13525 dst[7] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13526 dst[6] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13527 dst[5] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13528 dst[4] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13529 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13530 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13531 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13532 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13533 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13534 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13535 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13536 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13537 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13538 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13539
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13540 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13541 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13542 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13543 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13544 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13545
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13546 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13547 SDL_Downsample_S32MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13548 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13549 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13550 fprintf(stderr, "Downsample (x2) AUDIO_S32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13551 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13552
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13553 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13554 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13555 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13556 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13557 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13558 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13559 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13560 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13561 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13562 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13563 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13564 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13565 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13566 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13567 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13568 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13569 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13570 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13571 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13572 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13573 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13574 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13575 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13576 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13577 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13578
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13579 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13580 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13581 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13582 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13583 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13584
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13585 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13586 SDL_Upsample_S32MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13587 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13588 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13589 fprintf(stderr, "Upsample (x4) AUDIO_S32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13590 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13591
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13592 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13593 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13594 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13595 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13596 const Sint32 *target = ((const Sint32 *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13597 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13598 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13599 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13600 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13601 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13602 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13603 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13604 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13605 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13606 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13607 dst[15] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13608 dst[14] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13609 dst[13] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13610 dst[12] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13611 dst[11] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13612 dst[10] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13613 dst[9] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13614 dst[8] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13615 dst[7] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13616 dst[6] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13617 dst[5] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13618 dst[4] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13619 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13620 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13621 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13622 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13623 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13624 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13625 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13626 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13627 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13628 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13629
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13630 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13631 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13632 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13633 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13634 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13635
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13636 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13637 SDL_Downsample_S32MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13638 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13639 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13640 fprintf(stderr, "Downsample (x4) AUDIO_S32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13641 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13642
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13643 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13644 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13645 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13646 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13647 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13648 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13649 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13650 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13651 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13652 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13653 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13654 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13655 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13656 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13657 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13658 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13659 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13660 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13661 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13662 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13663 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13664 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13665 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13666 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13667 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13668
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13669 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13670 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13671 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13672 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13673 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13674
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13675 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13676 SDL_Upsample_S32MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13677 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13678 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13679 fprintf(stderr, "Upsample (x2) AUDIO_S32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13680 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13681
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13682 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13683 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13684 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13685 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13686 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13687 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13688 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13689 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13690 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13691 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13692 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13693 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13694 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13695 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13696 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13697 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13698 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13699 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13700 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13701 dst[11] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13702 dst[10] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13703 dst[9] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13704 dst[8] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13705 dst[7] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13706 dst[6] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13707 dst[5] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13708 dst[4] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13709 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13710 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13711 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13712 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13713 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13714 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13715 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13716 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13717 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13718 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13719 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13720 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13721
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13722 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13723 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13724 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13725 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13726 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13727
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13728 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13729 SDL_Downsample_S32MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13730 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13731 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13732 fprintf(stderr, "Downsample (x2) AUDIO_S32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13733 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13734
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13735 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13736 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13737 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13738 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13739 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13740 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13741 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13742 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13743 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13744 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13745 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13746 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13747 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13748 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13749 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13750 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13751 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13752 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13753 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13754 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13755 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13756 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13757 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13758 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13759 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13760 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13761 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13762 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13763 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13764 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13765 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13766 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13767 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13768
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13769 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13770 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13771 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13772 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13773 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13774
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13775 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13776 SDL_Upsample_S32MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13777 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13778 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13779 fprintf(stderr, "Upsample (x4) AUDIO_S32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13780 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13781
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13782 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13783 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13784 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13785 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13786 const Sint32 *target = ((const Sint32 *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13787 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13788 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13789 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13790 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13791 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13792 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13793 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13794 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13795 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13796 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13797 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13798 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13799 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13800 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13801 dst[23] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13802 dst[22] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13803 dst[21] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13804 dst[20] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13805 dst[19] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13806 dst[18] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13807 dst[17] = (Sint32) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13808 dst[16] = (Sint32) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13809 dst[15] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13810 dst[14] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13811 dst[13] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13812 dst[12] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13813 dst[11] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13814 dst[10] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13815 dst[9] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13816 dst[8] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13817 dst[7] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13818 dst[6] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13819 dst[5] = (Sint32) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13820 dst[4] = (Sint32) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13821 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13822 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13823 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13824 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13825 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13826 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13827 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13828 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13829 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13830 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13831 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13832 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13833
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13834 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13835 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13836 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13837 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13838 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13839
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13840 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13841 SDL_Downsample_S32MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13842 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13843 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13844 fprintf(stderr, "Downsample (x4) AUDIO_S32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13845 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13846
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13847 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13848 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13849 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13850 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13851 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13852 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13853 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13854 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13855 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13856 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13857 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13858 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13859 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13860 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13861 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13862 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13863 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13864 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13865 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13866 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13867 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13868 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13869 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13870 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13871 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13872 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13873 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13874 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13875 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13876 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13877 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13878 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13879 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13880
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13881 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13882 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13883 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13884 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13885 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13886
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13887 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13888 SDL_Upsample_S32MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13889 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13890 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13891 fprintf(stderr, "Upsample (x2) AUDIO_S32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13892 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13893
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13894 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13895 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13896 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13897 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13898 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13899 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13900 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13901 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13902 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13903 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13904 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13905 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13906 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13907 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13908 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13909 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13910 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13911 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13912 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13913 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13914 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13915 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13916 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13917 dst[15] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13918 dst[14] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13919 dst[13] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13920 dst[12] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13921 dst[11] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13922 dst[10] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13923 dst[9] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13924 dst[8] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13925 dst[7] = (Sint32) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13926 dst[6] = (Sint32) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13927 dst[5] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13928 dst[4] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13929 dst[3] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13930 dst[2] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13931 dst[1] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13932 dst[0] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13933 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13934 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13935 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13936 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13937 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13938 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13939 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13940 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13941 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13942 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13943
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13944 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13945 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13946 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13947 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13948 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13949
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13950 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13951 SDL_Downsample_S32MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13952 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
13953 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13954 fprintf(stderr, "Downsample (x2) AUDIO_S32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13955 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13956
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13957 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13958 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13959 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13960 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13961 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13962 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13963 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13964 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13965 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13966 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13967 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13968 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13969 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
13970 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13971 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13972 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13973 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13974 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13975 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13976 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13977 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13978 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13979 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13980 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13981 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13982 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13983 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13984 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13985 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13986 dst[6] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13987 dst[7] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13988 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13989 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13990 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13991 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13992 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13993 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13994 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13995 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13996 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13997 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13998
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
13999 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14000 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14001 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14002 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14003 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14004
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14005 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14006 SDL_Upsample_S32MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14007 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14008 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14009 fprintf(stderr, "Upsample (x4) AUDIO_S32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14010 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14011
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14012 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14013 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14014 Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14015 const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14016 const Sint32 *target = ((const Sint32 *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14017 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14018 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14019 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14020 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14021 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14022 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14023 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14024 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14025 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14026 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14027 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14028 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14029 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14030 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14031 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14032 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14033 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14034 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14035 dst[31] = (Sint32) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14036 dst[30] = (Sint32) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14037 dst[29] = (Sint32) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14038 dst[28] = (Sint32) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14039 dst[27] = (Sint32) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14040 dst[26] = (Sint32) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14041 dst[25] = (Sint32) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14042 dst[24] = (Sint32) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14043 dst[23] = (Sint32) (((3 * sample7) + last_sample7) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14044 dst[22] = (Sint32) (((3 * sample6) + last_sample6) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14045 dst[21] = (Sint32) (((3 * sample5) + last_sample5) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14046 dst[20] = (Sint32) (((3 * sample4) + last_sample4) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14047 dst[19] = (Sint32) (((3 * sample3) + last_sample3) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14048 dst[18] = (Sint32) (((3 * sample2) + last_sample2) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14049 dst[17] = (Sint32) (((3 * sample1) + last_sample1) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14050 dst[16] = (Sint32) (((3 * sample0) + last_sample0) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14051 dst[15] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14052 dst[14] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14053 dst[13] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14054 dst[12] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14055 dst[11] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14056 dst[10] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14057 dst[9] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14058 dst[8] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14059 dst[7] = (Sint32) ((sample7 + (3 * last_sample7)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14060 dst[6] = (Sint32) ((sample6 + (3 * last_sample6)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14061 dst[5] = (Sint32) ((sample5 + (3 * last_sample5)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14062 dst[4] = (Sint32) ((sample4 + (3 * last_sample4)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14063 dst[3] = (Sint32) ((sample3 + (3 * last_sample3)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14064 dst[2] = (Sint32) ((sample2 + (3 * last_sample2)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14065 dst[1] = (Sint32) ((sample1 + (3 * last_sample1)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14066 dst[0] = (Sint32) ((sample0 + (3 * last_sample0)) >> 2);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14067 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14068 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14069 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14070 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14071 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14072 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14073 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14074 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14075 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14076 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14077
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14078 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14079 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14080 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14081 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14082 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14083
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14084 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14085 SDL_Downsample_S32MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14086 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14087 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14088 fprintf(stderr, "Downsample (x4) AUDIO_S32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14089 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14090
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14091 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14092 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14093 Sint32 *dst = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14094 const Sint32 *src = (Sint32 *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14095 const Sint32 *target = (const Sint32 *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14096 Sint64 last_sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14097 Sint64 last_sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14098 Sint64 last_sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14099 Sint64 last_sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14100 Sint64 last_sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14101 Sint64 last_sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14102 Sint64 last_sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14103 Sint64 last_sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14104 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14105 const Sint64 sample0 = (Sint64) ((Sint32) SDL_SwapBE32(src[0]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14106 const Sint64 sample1 = (Sint64) ((Sint32) SDL_SwapBE32(src[1]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14107 const Sint64 sample2 = (Sint64) ((Sint32) SDL_SwapBE32(src[2]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14108 const Sint64 sample3 = (Sint64) ((Sint32) SDL_SwapBE32(src[3]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14109 const Sint64 sample4 = (Sint64) ((Sint32) SDL_SwapBE32(src[4]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14110 const Sint64 sample5 = (Sint64) ((Sint32) SDL_SwapBE32(src[5]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14111 const Sint64 sample6 = (Sint64) ((Sint32) SDL_SwapBE32(src[6]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14112 const Sint64 sample7 = (Sint64) ((Sint32) SDL_SwapBE32(src[7]));
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14113 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14114 dst[0] = (Sint32) ((sample0 + last_sample0) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14115 dst[1] = (Sint32) ((sample1 + last_sample1) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14116 dst[2] = (Sint32) ((sample2 + last_sample2) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14117 dst[3] = (Sint32) ((sample3 + last_sample3) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14118 dst[4] = (Sint32) ((sample4 + last_sample4) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14119 dst[5] = (Sint32) ((sample5 + last_sample5) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14120 dst[6] = (Sint32) ((sample6 + last_sample6) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14121 dst[7] = (Sint32) ((sample7 + last_sample7) >> 1);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14122 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14123 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14124 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14125 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14126 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14127 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14128 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14129 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14130 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14131 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14132
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14133 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14134 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14135 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14136 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14137 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14138
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14139 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14140 SDL_Upsample_F32LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14141 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14142 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14143 fprintf(stderr, "Upsample (x2) AUDIO_F32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14144 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14145
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14146 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14147 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14148 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14149 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14150 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14151 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14152 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14153 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14154 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14155 dst[1] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14156 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14157 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14158 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14159 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14160
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14161 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14162 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14163 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14164 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14165 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14166
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14167 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14168 SDL_Downsample_F32LSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14169 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14170 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14171 fprintf(stderr, "Downsample (x2) AUDIO_F32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14172 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14173
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14174 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14175 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14176 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14177 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14178 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14179 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14180 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14181 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14182 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14183 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14184 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14185 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14186 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14187
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14188 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14189 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14190 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14191 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14192 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14193
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14194 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14195 SDL_Upsample_F32LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14196 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14197 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14198 fprintf(stderr, "Upsample (x4) AUDIO_F32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14199 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14200
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14201 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14202 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14203 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14204 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14205 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14206 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14207 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14208 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14209 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14210 dst[3] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14211 dst[2] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14212 dst[1] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14213 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14214 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14215 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14216 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14217
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14218 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14219 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14220 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14221 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14222 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14223
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14224 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14225 SDL_Downsample_F32LSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14226 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14227 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14228 fprintf(stderr, "Downsample (x4) AUDIO_F32LSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14229 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14230
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14231 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14232 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14233 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14234 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14235 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14236 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14237 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14238 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14239 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14240 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14241 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14242 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14243 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14244
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14245 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14246 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14247 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14248 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14249 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14250
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14251 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14252 SDL_Upsample_F32LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14253 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14254 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14255 fprintf(stderr, "Upsample (x2) AUDIO_F32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14256 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14257
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14258 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14259 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14260 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14261 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14262 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14263 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14264 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14265 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14266 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14267 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14268 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14269 dst[3] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14270 dst[2] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14271 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14272 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14273 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14274 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14275 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14276 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14277
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14278 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14279 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14280 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14281 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14282 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14283
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14284 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14285 SDL_Downsample_F32LSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14286 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14287 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14288 fprintf(stderr, "Downsample (x2) AUDIO_F32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14289 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14290
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14291 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14292 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14293 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14294 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14295 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14296 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14297 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14298 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14299 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14300 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14301 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14302 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14303 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14304 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14305 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14306 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14307 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14308
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14309 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14310 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14311 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14312 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14313 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14314
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14315 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14316 SDL_Upsample_F32LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14317 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14318 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14319 fprintf(stderr, "Upsample (x4) AUDIO_F32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14320 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14321
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14322 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14323 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14324 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14325 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14326 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14327 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14328 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14329 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14330 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14331 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14332 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14333 dst[7] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14334 dst[6] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14335 dst[5] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14336 dst[4] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14337 dst[3] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14338 dst[2] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14339 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14340 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14341 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14342 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14343 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14344 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14345
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14346 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14347 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14348 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14349 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14350 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14351
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14352 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14353 SDL_Downsample_F32LSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14354 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14355 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14356 fprintf(stderr, "Downsample (x4) AUDIO_F32LSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14357 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14358
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14359 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14360 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14361 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14362 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14363 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14364 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14365 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14366 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14367 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14368 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14369 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14370 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14371 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14372 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14373 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14374 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14375 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14376
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14377 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14378 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14379 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14380 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14381 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14382
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14383 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14384 SDL_Upsample_F32LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14385 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14386 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14387 fprintf(stderr, "Upsample (x2) AUDIO_F32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14388 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14389
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14390 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14391 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14392 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14393 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14394 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14395 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14396 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14397 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14398 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14399 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14400 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14401 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14402 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14403 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14404 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14405 dst[7] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14406 dst[6] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14407 dst[5] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14408 dst[4] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14409 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14410 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14411 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14412 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14413 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14414 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14415 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14416 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14417 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14418 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14419
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14420 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14421 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14422 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14423 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14424 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14425
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14426 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14427 SDL_Downsample_F32LSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14428 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14429 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14430 fprintf(stderr, "Downsample (x2) AUDIO_F32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14431 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14432
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14433 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14434 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14435 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14436 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14437 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14438 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14439 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14440 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14441 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14442 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14443 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14444 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14445 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14446 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14447 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14448 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14449 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14450 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14451 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14452 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14453 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14454 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14455 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14456 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14457 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14458
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14459 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14460 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14461 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14462 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14463 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14464
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14465 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14466 SDL_Upsample_F32LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14467 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14468 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14469 fprintf(stderr, "Upsample (x4) AUDIO_F32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14470 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14471
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14472 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14473 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14474 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14475 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14476 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14477 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14478 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14479 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14480 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14481 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14482 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14483 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14484 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14485 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14486 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14487 dst[15] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14488 dst[14] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14489 dst[13] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14490 dst[12] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14491 dst[11] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14492 dst[10] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14493 dst[9] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14494 dst[8] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14495 dst[7] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14496 dst[6] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14497 dst[5] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14498 dst[4] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14499 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14500 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14501 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14502 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14503 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14504 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14505 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14506 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14507 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14508 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14509
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14510 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14511 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14512 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14513 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14514 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14515
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14516 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14517 SDL_Downsample_F32LSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14518 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14519 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14520 fprintf(stderr, "Downsample (x4) AUDIO_F32LSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14521 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14522
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14523 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14524 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14525 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14526 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14527 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14528 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14529 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14530 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14531 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14532 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14533 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14534 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14535 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14536 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14537 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14538 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14539 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14540 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14541 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14542 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14543 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14544 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14545 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14546 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14547 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14548
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14549 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14550 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14551 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14552 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14553 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14554
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14555 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14556 SDL_Upsample_F32LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14557 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14558 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14559 fprintf(stderr, "Upsample (x2) AUDIO_F32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14560 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14561
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14562 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14563 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14564 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14565 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14566 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14567 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14568 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14569 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14570 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14571 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14572 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14573 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14574 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14575 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14576 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14577 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14578 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14579 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14580 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14581 dst[11] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14582 dst[10] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14583 dst[9] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14584 dst[8] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14585 dst[7] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14586 dst[6] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14587 dst[5] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14588 dst[4] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14589 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14590 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14591 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14592 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14593 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14594 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14595 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14596 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14597 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14598 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14599 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14600 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14601
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14602 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14603 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14604 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14605 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14606 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14607
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14608 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14609 SDL_Downsample_F32LSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14610 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14611 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14612 fprintf(stderr, "Downsample (x2) AUDIO_F32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14613 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14614
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14615 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14616 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14617 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14618 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14619 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14620 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14621 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14622 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14623 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14624 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14625 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14626 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14627 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14628 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14629 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14630 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14631 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14632 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14633 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14634 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14635 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14636 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14637 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14638 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14639 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14640 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14641 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14642 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14643 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14644 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14645 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14646 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14647 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14648
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14649 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14650 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14651 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14652 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14653 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14654
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14655 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14656 SDL_Upsample_F32LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14657 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14658 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14659 fprintf(stderr, "Upsample (x4) AUDIO_F32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14660 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14661
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14662 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14663 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14664 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14665 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14666 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14667 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14668 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14669 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14670 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14671 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14672 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14673 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14674 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14675 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14676 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14677 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14678 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14679 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14680 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14681 dst[23] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14682 dst[22] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14683 dst[21] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14684 dst[20] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14685 dst[19] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14686 dst[18] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14687 dst[17] = (float) (((3.0 * sample5) + last_sample5) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14688 dst[16] = (float) (((3.0 * sample4) + last_sample4) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14689 dst[15] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14690 dst[14] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14691 dst[13] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14692 dst[12] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14693 dst[11] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14694 dst[10] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14695 dst[9] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14696 dst[8] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14697 dst[7] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14698 dst[6] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14699 dst[5] = (float) ((sample5 + (3.0 * last_sample5)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14700 dst[4] = (float) ((sample4 + (3.0 * last_sample4)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14701 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14702 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14703 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14704 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14705 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14706 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14707 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14708 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14709 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14710 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14711 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14712 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14713
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14714 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14715 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14716 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14717 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14718 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14719
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14720 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14721 SDL_Downsample_F32LSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14722 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14723 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14724 fprintf(stderr, "Downsample (x4) AUDIO_F32LSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14725 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14726
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14727 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14728 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14729 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14730 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14731 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14732 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14733 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14734 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14735 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14736 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14737 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14738 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14739 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14740 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14741 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14742 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14743 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14744 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14745 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14746 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14747 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14748 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14749 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14750 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14751 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14752 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14753 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14754 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14755 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14756 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14757 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14758 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14759 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14760
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14761 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14762 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14763 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14764 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14765 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14766
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14767 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14768 SDL_Upsample_F32LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14769 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14770 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14771 fprintf(stderr, "Upsample (x2) AUDIO_F32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14772 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14773
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14774 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14775 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14776 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14777 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14778 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14779 double last_sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14780 double last_sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14781 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14782 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14783 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14784 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14785 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14786 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14787 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14788 const double sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14789 const double sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14790 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14791 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14792 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14793 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14794 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14795 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14796 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14797 dst[15] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14798 dst[14] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14799 dst[13] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14800 dst[12] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14801 dst[11] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14802 dst[10] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14803 dst[9] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14804 dst[8] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14805 dst[7] = (float) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14806 dst[6] = (float) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14807 dst[5] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14808 dst[4] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14809 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14810 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14811 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14812 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14813 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14814 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14815 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14816 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14817 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14818 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14819 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14820 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14821 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14822 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14823
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14824 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14825 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14826 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14827 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14828 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14829
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14830 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14831 SDL_Downsample_F32LSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14832 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14833 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14834 fprintf(stderr, "Downsample (x2) AUDIO_F32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14835 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14836
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14837 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14838 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14839 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14840 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14841 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14842 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14843 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14844 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14845 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14846 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14847 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14848 double last_sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14849 double last_sample7 = (double) SDL_SwapFloatLE(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14850 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14851 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14852 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14853 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14854 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14855 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14856 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14857 const double sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14858 const double sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14859 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14860 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14861 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14862 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14863 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14864 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14865 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14866 dst[6] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14867 dst[7] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14868 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14869 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14870 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14871 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14872 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14873 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14874 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14875 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14876 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14877 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14878
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14879 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14880 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14881 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14882 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14883 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14884
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14885 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14886 SDL_Upsample_F32LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14887 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14888 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14889 fprintf(stderr, "Upsample (x4) AUDIO_F32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14890 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14891
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14892 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14893 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14894 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14895 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14896 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14897 double last_sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14898 double last_sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14899 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14900 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14901 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14902 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14903 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14904 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14905 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14906 const double sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14907 const double sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14908 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14909 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14910 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14911 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14912 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14913 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14914 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14915 dst[31] = (float) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14916 dst[30] = (float) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14917 dst[29] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14918 dst[28] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14919 dst[27] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14920 dst[26] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14921 dst[25] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14922 dst[24] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14923 dst[23] = (float) (((3.0 * sample7) + last_sample7) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14924 dst[22] = (float) (((3.0 * sample6) + last_sample6) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14925 dst[21] = (float) (((3.0 * sample5) + last_sample5) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14926 dst[20] = (float) (((3.0 * sample4) + last_sample4) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14927 dst[19] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14928 dst[18] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14929 dst[17] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14930 dst[16] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14931 dst[15] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14932 dst[14] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14933 dst[13] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14934 dst[12] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14935 dst[11] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14936 dst[10] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14937 dst[9] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14938 dst[8] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14939 dst[7] = (float) ((sample7 + (3.0 * last_sample7)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14940 dst[6] = (float) ((sample6 + (3.0 * last_sample6)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14941 dst[5] = (float) ((sample5 + (3.0 * last_sample5)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14942 dst[4] = (float) ((sample4 + (3.0 * last_sample4)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14943 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14944 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14945 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14946 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14947 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14948 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14949 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14950 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14951 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14952 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14953 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14954 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14955 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14956 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14957
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14958 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14959 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14960 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14961 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14962 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14963
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14964 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14965 SDL_Downsample_F32LSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14966 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
14967 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14968 fprintf(stderr, "Downsample (x4) AUDIO_F32LSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14969 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14970
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14971 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14972 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14973 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14974 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14975 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14976 double last_sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14977 double last_sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14978 double last_sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14979 double last_sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14980 double last_sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14981 double last_sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14982 double last_sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14983 double last_sample7 = (double) SDL_SwapFloatLE(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
14984 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14985 const double sample0 = (double) SDL_SwapFloatLE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14986 const double sample1 = (double) SDL_SwapFloatLE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14987 const double sample2 = (double) SDL_SwapFloatLE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14988 const double sample3 = (double) SDL_SwapFloatLE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14989 const double sample4 = (double) SDL_SwapFloatLE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14990 const double sample5 = (double) SDL_SwapFloatLE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14991 const double sample6 = (double) SDL_SwapFloatLE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14992 const double sample7 = (double) SDL_SwapFloatLE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14993 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14994 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14995 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14996 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14997 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14998 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
14999 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15000 dst[6] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15001 dst[7] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15002 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15003 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15004 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15005 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15006 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15007 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15008 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15009 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15010 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15011 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15012
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15013 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15014 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15015 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15016 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15017 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15018
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15019 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15020 SDL_Upsample_F32MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15021 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15022 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15023 fprintf(stderr, "Upsample (x2) AUDIO_F32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15024 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15025
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15026 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15027 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15028 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15029 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15030 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15031 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15032 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15033 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15034 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15035 dst[1] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15036 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15037 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15038 dst -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15039 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15040
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15041 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15042 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15043 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15044 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15045 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15046
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15047 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15048 SDL_Downsample_F32MSB_1c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15049 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15050 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15051 fprintf(stderr, "Downsample (x2) AUDIO_F32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15052 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15053
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15054 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15055 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15056 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15057 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15058 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15059 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15060 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15061 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15062 src += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15063 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15064 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15065 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15066 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15067
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15068 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15069 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15070 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15071 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15072 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15073
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15074 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15075 SDL_Upsample_F32MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15076 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15077 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15078 fprintf(stderr, "Upsample (x4) AUDIO_F32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15079 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15080
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15081 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15082 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15083 float *dst = ((float *) (cvt->buf + dstsize)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15084 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15085 const float *target = ((const float *) cvt->buf) - 1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15086 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15087 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15088 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15089 src--;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15090 dst[3] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15091 dst[2] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15092 dst[1] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15093 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15094 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15095 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15096 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15097
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15098 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15099 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15100 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15101 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15102 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15103
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15104 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15105 SDL_Downsample_F32MSB_1c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15106 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15107 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15108 fprintf(stderr, "Downsample (x4) AUDIO_F32MSB, 1 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15109 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15110
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15111 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15112 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15113 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15114 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15115 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15116 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15117 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15118 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15119 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15120 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15121 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15122 dst++;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15123 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15124
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15125 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15126 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15127 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15128 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15129 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15130
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15131 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15132 SDL_Upsample_F32MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15133 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15134 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15135 fprintf(stderr, "Upsample (x2) AUDIO_F32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15136 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15137
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15138 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15139 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15140 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15141 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15142 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15143 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15144 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15145 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15146 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15147 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15148 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15149 dst[3] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15150 dst[2] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15151 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15152 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15153 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15154 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15155 dst -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15156 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15157
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15158 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15159 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15160 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15161 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15162 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15163
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15164 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15165 SDL_Downsample_F32MSB_2c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15166 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15167 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15168 fprintf(stderr, "Downsample (x2) AUDIO_F32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15169 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15170
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15171 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15172 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15173 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15174 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15175 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15176 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15177 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15178 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15179 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15180 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15181 src += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15182 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15183 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15184 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15185 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15186 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15187 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15188
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15189 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15190 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15191 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15192 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15193 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15194
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15195 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15196 SDL_Upsample_F32MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15197 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15198 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15199 fprintf(stderr, "Upsample (x4) AUDIO_F32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15200 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15201
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15202 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15203 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15204 float *dst = ((float *) (cvt->buf + dstsize)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15205 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15206 const float *target = ((const float *) cvt->buf) - 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15207 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15208 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15209 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15210 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15211 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15212 src -= 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15213 dst[7] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15214 dst[6] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15215 dst[5] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15216 dst[4] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15217 dst[3] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15218 dst[2] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15219 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15220 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15221 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15222 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15223 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15224 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15225
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15226 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15227 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15228 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15229 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15230 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15231
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15232 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15233 SDL_Downsample_F32MSB_2c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15234 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15235 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15236 fprintf(stderr, "Downsample (x4) AUDIO_F32MSB, 2 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15237 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15238
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15239 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15240 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15241 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15242 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15243 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15244 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15245 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15246 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15247 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15248 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15249 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15250 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15251 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15252 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15253 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15254 dst += 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15255 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15256
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15257 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15258 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15259 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15260 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15261 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15262
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15263 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15264 SDL_Upsample_F32MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15265 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15266 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15267 fprintf(stderr, "Upsample (x2) AUDIO_F32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15268 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15269
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15270 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15271 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15272 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15273 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15274 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15275 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15276 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15277 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15278 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15279 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15280 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15281 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15282 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15283 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15284 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15285 dst[7] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15286 dst[6] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15287 dst[5] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15288 dst[4] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15289 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15290 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15291 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15292 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15293 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15294 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15295 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15296 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15297 dst -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15298 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15299
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15300 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15301 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15302 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15303 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15304 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15305
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15306 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15307 SDL_Downsample_F32MSB_4c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15308 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15309 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15310 fprintf(stderr, "Downsample (x2) AUDIO_F32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15311 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15312
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15313 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15314 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15315 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15316 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15317 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15318 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15319 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15320 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15321 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15322 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15323 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15324 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15325 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15326 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15327 src += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15328 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15329 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15330 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15331 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15332 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15333 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15334 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15335 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15336 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15337 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15338
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15339 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15340 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15341 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15342 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15343 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15344
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15345 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15346 SDL_Upsample_F32MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15347 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15348 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15349 fprintf(stderr, "Upsample (x4) AUDIO_F32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15350 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15351
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15352 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15353 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15354 float *dst = ((float *) (cvt->buf + dstsize)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15355 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15356 const float *target = ((const float *) cvt->buf) - 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15357 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15358 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15359 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15360 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15361 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15362 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15363 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15364 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15365 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15366 src -= 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15367 dst[15] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15368 dst[14] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15369 dst[13] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15370 dst[12] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15371 dst[11] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15372 dst[10] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15373 dst[9] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15374 dst[8] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15375 dst[7] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15376 dst[6] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15377 dst[5] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15378 dst[4] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15379 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15380 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15381 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15382 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15383 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15384 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15385 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15386 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15387 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15388 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15389
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15390 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15391 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15392 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15393 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15394 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15395
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15396 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15397 SDL_Downsample_F32MSB_4c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15398 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15399 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15400 fprintf(stderr, "Downsample (x4) AUDIO_F32MSB, 4 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15401 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15402
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15403 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15404 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15405 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15406 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15407 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15408 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15409 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15410 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15411 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15412 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15413 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15414 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15415 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15416 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15417 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15418 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15419 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15420 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15421 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15422 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15423 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15424 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15425 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15426 dst += 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15427 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15428
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15429 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15430 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15431 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15432 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15433 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15434
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15435 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15436 SDL_Upsample_F32MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15437 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15438 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15439 fprintf(stderr, "Upsample (x2) AUDIO_F32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15440 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15441
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15442 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15443 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15444 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15445 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15446 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15447 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15448 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15449 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15450 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15451 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15452 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15453 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15454 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15455 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15456 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15457 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15458 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15459 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15460 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15461 dst[11] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15462 dst[10] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15463 dst[9] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15464 dst[8] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15465 dst[7] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15466 dst[6] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15467 dst[5] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15468 dst[4] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15469 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15470 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15471 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15472 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15473 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15474 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15475 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15476 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15477 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15478 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15479 dst -= 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15480 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15481
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15482 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15483 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15484 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15485 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15486 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15487
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15488 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15489 SDL_Downsample_F32MSB_6c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15490 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15491 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15492 fprintf(stderr, "Downsample (x2) AUDIO_F32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15493 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15494
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15495 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15496 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15497 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15498 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15499 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15500 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15501 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15502 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15503 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15504 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15505 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15506 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15507 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15508 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15509 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15510 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15511 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15512 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15513 src += 12;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15514 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15515 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15516 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15517 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15518 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15519 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15520 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15521 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15522 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15523 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15524 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15525 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15526 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15527 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15528
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15529 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15530 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15531 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15532 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15533 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15534
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15535 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15536 SDL_Upsample_F32MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15537 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15538 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15539 fprintf(stderr, "Upsample (x4) AUDIO_F32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15540 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15541
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15542 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15543 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15544 float *dst = ((float *) (cvt->buf + dstsize)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15545 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15546 const float *target = ((const float *) cvt->buf) - 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15547 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15548 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15549 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15550 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15551 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15552 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15553 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15554 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15555 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15556 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15557 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15558 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15559 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15560 src -= 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15561 dst[23] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15562 dst[22] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15563 dst[21] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15564 dst[20] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15565 dst[19] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15566 dst[18] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15567 dst[17] = (float) (((3.0 * sample5) + last_sample5) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15568 dst[16] = (float) (((3.0 * sample4) + last_sample4) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15569 dst[15] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15570 dst[14] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15571 dst[13] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15572 dst[12] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15573 dst[11] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15574 dst[10] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15575 dst[9] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15576 dst[8] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15577 dst[7] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15578 dst[6] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15579 dst[5] = (float) ((sample5 + (3.0 * last_sample5)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15580 dst[4] = (float) ((sample4 + (3.0 * last_sample4)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15581 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15582 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15583 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15584 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15585 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15586 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15587 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15588 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15589 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15590 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15591 dst -= 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15592 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15593
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15594 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15595 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15596 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15597 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15598 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15599
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15600 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15601 SDL_Downsample_F32MSB_6c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15602 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15603 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15604 fprintf(stderr, "Downsample (x4) AUDIO_F32MSB, 6 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15605 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15606
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15607 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15608 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15609 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15610 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15611 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15612 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15613 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15614 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15615 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15616 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15617 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15618 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15619 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15620 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15621 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15622 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15623 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15624 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15625 src += 24;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15626 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15627 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15628 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15629 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15630 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15631 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15632 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15633 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15634 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15635 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15636 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15637 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15638 dst += 6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15639 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15640
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15641 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15642 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15643 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15644 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15645 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15646
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15647 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15648 SDL_Upsample_F32MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15649 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15650 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15651 fprintf(stderr, "Upsample (x2) AUDIO_F32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15652 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15653
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15654 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15655 const int dstsize = cvt->len_cvt * 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15656 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15657 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15658 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15659 double last_sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15660 double last_sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15661 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15662 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15663 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15664 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15665 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15666 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15667 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15668 const double sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15669 const double sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15670 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15671 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15672 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15673 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15674 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15675 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15676 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15677 dst[15] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15678 dst[14] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15679 dst[13] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15680 dst[12] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15681 dst[11] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15682 dst[10] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15683 dst[9] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15684 dst[8] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15685 dst[7] = (float) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15686 dst[6] = (float) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15687 dst[5] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15688 dst[4] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15689 dst[3] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15690 dst[2] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15691 dst[1] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15692 dst[0] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15693 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15694 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15695 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15696 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15697 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15698 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15699 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15700 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15701 dst -= 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15702 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15703
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15704 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15705 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15706 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15707 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15708 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15709
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15710 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15711 SDL_Downsample_F32MSB_8c_x2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15712 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15713 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15714 fprintf(stderr, "Downsample (x2) AUDIO_F32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15715 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15716
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15717 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15718 const int dstsize = cvt->len_cvt / 2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15719 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15720 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15721 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15722 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15723 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15724 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15725 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15726 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15727 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15728 double last_sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15729 double last_sample7 = (double) SDL_SwapFloatBE(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15730 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15731 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15732 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15733 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15734 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15735 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15736 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15737 const double sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15738 const double sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15739 src += 16;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15740 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15741 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15742 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15743 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15744 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15745 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15746 dst[6] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15747 dst[7] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15748 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15749 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15750 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15751 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15752 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15753 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15754 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15755 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15756 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15757 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15758
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15759 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15760 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15761 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15762 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15763 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15764
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15765 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15766 SDL_Upsample_F32MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15767 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15768 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15769 fprintf(stderr, "Upsample (x4) AUDIO_F32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15770 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15771
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15772 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15773 const int dstsize = cvt->len_cvt * 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15774 float *dst = ((float *) (cvt->buf + dstsize)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15775 const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15776 const float *target = ((const float *) cvt->buf) - 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15777 double last_sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15778 double last_sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15779 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15780 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15781 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15782 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15783 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15784 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15785 while (dst > target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15786 const double sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15787 const double sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15788 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15789 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15790 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15791 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15792 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15793 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15794 src -= 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15795 dst[31] = (float) sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15796 dst[30] = (float) sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15797 dst[29] = (float) sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15798 dst[28] = (float) sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15799 dst[27] = (float) sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15800 dst[26] = (float) sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15801 dst[25] = (float) sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15802 dst[24] = (float) sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15803 dst[23] = (float) (((3.0 * sample7) + last_sample7) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15804 dst[22] = (float) (((3.0 * sample6) + last_sample6) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15805 dst[21] = (float) (((3.0 * sample5) + last_sample5) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15806 dst[20] = (float) (((3.0 * sample4) + last_sample4) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15807 dst[19] = (float) (((3.0 * sample3) + last_sample3) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15808 dst[18] = (float) (((3.0 * sample2) + last_sample2) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15809 dst[17] = (float) (((3.0 * sample1) + last_sample1) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15810 dst[16] = (float) (((3.0 * sample0) + last_sample0) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15811 dst[15] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15812 dst[14] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15813 dst[13] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15814 dst[12] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15815 dst[11] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15816 dst[10] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15817 dst[9] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15818 dst[8] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15819 dst[7] = (float) ((sample7 + (3.0 * last_sample7)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15820 dst[6] = (float) ((sample6 + (3.0 * last_sample6)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15821 dst[5] = (float) ((sample5 + (3.0 * last_sample5)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15822 dst[4] = (float) ((sample4 + (3.0 * last_sample4)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15823 dst[3] = (float) ((sample3 + (3.0 * last_sample3)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15824 dst[2] = (float) ((sample2 + (3.0 * last_sample2)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15825 dst[1] = (float) ((sample1 + (3.0 * last_sample1)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15826 dst[0] = (float) ((sample0 + (3.0 * last_sample0)) * 0.25);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15827 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15828 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15829 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15830 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15831 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15832 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15833 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15834 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15835 dst -= 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15836 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15837
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15838 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15839 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15840 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15841 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15842 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15843
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15844 static void SDLCALL
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15845 SDL_Downsample_F32MSB_8c_x4(SDL_AudioCVT * cvt, SDL_AudioFormat format)
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15846 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3021
diff changeset
15847 #if DEBUG_CONVERT
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15848 fprintf(stderr, "Downsample (x4) AUDIO_F32MSB, 8 channels.\n");
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15849 #endif
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15850
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15851 const int srcsize = cvt->len_cvt;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15852 const int dstsize = cvt->len_cvt / 4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15853 float *dst = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15854 const float *src = (float *) cvt->buf;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15855 const float *target = (const float *) (cvt->buf + dstsize);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15856 double last_sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15857 double last_sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15858 double last_sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15859 double last_sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15860 double last_sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15861 double last_sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15862 double last_sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15863 double last_sample7 = (double) SDL_SwapFloatBE(src[7]);
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
15864 while (dst < target) {
3021
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15865 const double sample0 = (double) SDL_SwapFloatBE(src[0]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15866 const double sample1 = (double) SDL_SwapFloatBE(src[1]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15867 const double sample2 = (double) SDL_SwapFloatBE(src[2]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15868 const double sample3 = (double) SDL_SwapFloatBE(src[3]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15869 const double sample4 = (double) SDL_SwapFloatBE(src[4]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15870 const double sample5 = (double) SDL_SwapFloatBE(src[5]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15871 const double sample6 = (double) SDL_SwapFloatBE(src[6]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15872 const double sample7 = (double) SDL_SwapFloatBE(src[7]);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15873 src += 32;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15874 dst[0] = (float) ((sample0 + last_sample0) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15875 dst[1] = (float) ((sample1 + last_sample1) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15876 dst[2] = (float) ((sample2 + last_sample2) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15877 dst[3] = (float) ((sample3 + last_sample3) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15878 dst[4] = (float) ((sample4 + last_sample4) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15879 dst[5] = (float) ((sample5 + last_sample5) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15880 dst[6] = (float) ((sample6 + last_sample6) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15881 dst[7] = (float) ((sample7 + last_sample7) * 0.5);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15882 last_sample0 = sample0;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15883 last_sample1 = sample1;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15884 last_sample2 = sample2;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15885 last_sample3 = sample3;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15886 last_sample4 = sample4;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15887 last_sample5 = sample5;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15888 last_sample6 = sample6;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15889 last_sample7 = sample7;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15890 dst += 8;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15891 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15892
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15893 cvt->len_cvt = dstsize;
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15894 if (cvt->filters[++cvt->filter_index]) {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15895 cvt->filters[cvt->filter_index] (cvt, format);
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15896 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15897 }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15898
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15899 #endif /* !LESS_RESAMPLERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15900 #endif /* !NO_RESAMPLERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15901
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15902
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15903 const SDL_AudioRateFilters sdl_audio_rate_filters[] =
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15904 {
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15905 #if !NO_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15906 { AUDIO_U8, 1, 0, 0, SDL_Downsample_U8_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15907 { AUDIO_U8, 1, 1, 0, SDL_Upsample_U8_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15908 { AUDIO_U8, 2, 0, 0, SDL_Downsample_U8_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15909 { AUDIO_U8, 2, 1, 0, SDL_Upsample_U8_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15910 { AUDIO_U8, 4, 0, 0, SDL_Downsample_U8_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15911 { AUDIO_U8, 4, 1, 0, SDL_Upsample_U8_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15912 { AUDIO_U8, 6, 0, 0, SDL_Downsample_U8_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15913 { AUDIO_U8, 6, 1, 0, SDL_Upsample_U8_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15914 { AUDIO_U8, 8, 0, 0, SDL_Downsample_U8_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15915 { AUDIO_U8, 8, 1, 0, SDL_Upsample_U8_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15916 { AUDIO_S8, 1, 0, 0, SDL_Downsample_S8_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15917 { AUDIO_S8, 1, 1, 0, SDL_Upsample_S8_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15918 { AUDIO_S8, 2, 0, 0, SDL_Downsample_S8_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15919 { AUDIO_S8, 2, 1, 0, SDL_Upsample_S8_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15920 { AUDIO_S8, 4, 0, 0, SDL_Downsample_S8_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15921 { AUDIO_S8, 4, 1, 0, SDL_Upsample_S8_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15922 { AUDIO_S8, 6, 0, 0, SDL_Downsample_S8_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15923 { AUDIO_S8, 6, 1, 0, SDL_Upsample_S8_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15924 { AUDIO_S8, 8, 0, 0, SDL_Downsample_S8_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15925 { AUDIO_S8, 8, 1, 0, SDL_Upsample_S8_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15926 { AUDIO_U16LSB, 1, 0, 0, SDL_Downsample_U16LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15927 { AUDIO_U16LSB, 1, 1, 0, SDL_Upsample_U16LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15928 { AUDIO_U16LSB, 2, 0, 0, SDL_Downsample_U16LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15929 { AUDIO_U16LSB, 2, 1, 0, SDL_Upsample_U16LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15930 { AUDIO_U16LSB, 4, 0, 0, SDL_Downsample_U16LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15931 { AUDIO_U16LSB, 4, 1, 0, SDL_Upsample_U16LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15932 { AUDIO_U16LSB, 6, 0, 0, SDL_Downsample_U16LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15933 { AUDIO_U16LSB, 6, 1, 0, SDL_Upsample_U16LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15934 { AUDIO_U16LSB, 8, 0, 0, SDL_Downsample_U16LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15935 { AUDIO_U16LSB, 8, 1, 0, SDL_Upsample_U16LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15936 { AUDIO_S16LSB, 1, 0, 0, SDL_Downsample_S16LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15937 { AUDIO_S16LSB, 1, 1, 0, SDL_Upsample_S16LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15938 { AUDIO_S16LSB, 2, 0, 0, SDL_Downsample_S16LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15939 { AUDIO_S16LSB, 2, 1, 0, SDL_Upsample_S16LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15940 { AUDIO_S16LSB, 4, 0, 0, SDL_Downsample_S16LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15941 { AUDIO_S16LSB, 4, 1, 0, SDL_Upsample_S16LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15942 { AUDIO_S16LSB, 6, 0, 0, SDL_Downsample_S16LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15943 { AUDIO_S16LSB, 6, 1, 0, SDL_Upsample_S16LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15944 { AUDIO_S16LSB, 8, 0, 0, SDL_Downsample_S16LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15945 { AUDIO_S16LSB, 8, 1, 0, SDL_Upsample_S16LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15946 { AUDIO_U16MSB, 1, 0, 0, SDL_Downsample_U16MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15947 { AUDIO_U16MSB, 1, 1, 0, SDL_Upsample_U16MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15948 { AUDIO_U16MSB, 2, 0, 0, SDL_Downsample_U16MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15949 { AUDIO_U16MSB, 2, 1, 0, SDL_Upsample_U16MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15950 { AUDIO_U16MSB, 4, 0, 0, SDL_Downsample_U16MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15951 { AUDIO_U16MSB, 4, 1, 0, SDL_Upsample_U16MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15952 { AUDIO_U16MSB, 6, 0, 0, SDL_Downsample_U16MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15953 { AUDIO_U16MSB, 6, 1, 0, SDL_Upsample_U16MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15954 { AUDIO_U16MSB, 8, 0, 0, SDL_Downsample_U16MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15955 { AUDIO_U16MSB, 8, 1, 0, SDL_Upsample_U16MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15956 { AUDIO_S16MSB, 1, 0, 0, SDL_Downsample_S16MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15957 { AUDIO_S16MSB, 1, 1, 0, SDL_Upsample_S16MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15958 { AUDIO_S16MSB, 2, 0, 0, SDL_Downsample_S16MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15959 { AUDIO_S16MSB, 2, 1, 0, SDL_Upsample_S16MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15960 { AUDIO_S16MSB, 4, 0, 0, SDL_Downsample_S16MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15961 { AUDIO_S16MSB, 4, 1, 0, SDL_Upsample_S16MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15962 { AUDIO_S16MSB, 6, 0, 0, SDL_Downsample_S16MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15963 { AUDIO_S16MSB, 6, 1, 0, SDL_Upsample_S16MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15964 { AUDIO_S16MSB, 8, 0, 0, SDL_Downsample_S16MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15965 { AUDIO_S16MSB, 8, 1, 0, SDL_Upsample_S16MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15966 { AUDIO_S32LSB, 1, 0, 0, SDL_Downsample_S32LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15967 { AUDIO_S32LSB, 1, 1, 0, SDL_Upsample_S32LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15968 { AUDIO_S32LSB, 2, 0, 0, SDL_Downsample_S32LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15969 { AUDIO_S32LSB, 2, 1, 0, SDL_Upsample_S32LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15970 { AUDIO_S32LSB, 4, 0, 0, SDL_Downsample_S32LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15971 { AUDIO_S32LSB, 4, 1, 0, SDL_Upsample_S32LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15972 { AUDIO_S32LSB, 6, 0, 0, SDL_Downsample_S32LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15973 { AUDIO_S32LSB, 6, 1, 0, SDL_Upsample_S32LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15974 { AUDIO_S32LSB, 8, 0, 0, SDL_Downsample_S32LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15975 { AUDIO_S32LSB, 8, 1, 0, SDL_Upsample_S32LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15976 { AUDIO_S32MSB, 1, 0, 0, SDL_Downsample_S32MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15977 { AUDIO_S32MSB, 1, 1, 0, SDL_Upsample_S32MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15978 { AUDIO_S32MSB, 2, 0, 0, SDL_Downsample_S32MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15979 { AUDIO_S32MSB, 2, 1, 0, SDL_Upsample_S32MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15980 { AUDIO_S32MSB, 4, 0, 0, SDL_Downsample_S32MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15981 { AUDIO_S32MSB, 4, 1, 0, SDL_Upsample_S32MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15982 { AUDIO_S32MSB, 6, 0, 0, SDL_Downsample_S32MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15983 { AUDIO_S32MSB, 6, 1, 0, SDL_Upsample_S32MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15984 { AUDIO_S32MSB, 8, 0, 0, SDL_Downsample_S32MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15985 { AUDIO_S32MSB, 8, 1, 0, SDL_Upsample_S32MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15986 { AUDIO_F32LSB, 1, 0, 0, SDL_Downsample_F32LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15987 { AUDIO_F32LSB, 1, 1, 0, SDL_Upsample_F32LSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15988 { AUDIO_F32LSB, 2, 0, 0, SDL_Downsample_F32LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15989 { AUDIO_F32LSB, 2, 1, 0, SDL_Upsample_F32LSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15990 { AUDIO_F32LSB, 4, 0, 0, SDL_Downsample_F32LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15991 { AUDIO_F32LSB, 4, 1, 0, SDL_Upsample_F32LSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15992 { AUDIO_F32LSB, 6, 0, 0, SDL_Downsample_F32LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15993 { AUDIO_F32LSB, 6, 1, 0, SDL_Upsample_F32LSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15994 { AUDIO_F32LSB, 8, 0, 0, SDL_Downsample_F32LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15995 { AUDIO_F32LSB, 8, 1, 0, SDL_Upsample_F32LSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15996 { AUDIO_F32MSB, 1, 0, 0, SDL_Downsample_F32MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15997 { AUDIO_F32MSB, 1, 1, 0, SDL_Upsample_F32MSB_1c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15998 { AUDIO_F32MSB, 2, 0, 0, SDL_Downsample_F32MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
15999 { AUDIO_F32MSB, 2, 1, 0, SDL_Upsample_F32MSB_2c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16000 { AUDIO_F32MSB, 4, 0, 0, SDL_Downsample_F32MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16001 { AUDIO_F32MSB, 4, 1, 0, SDL_Upsample_F32MSB_4c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16002 { AUDIO_F32MSB, 6, 0, 0, SDL_Downsample_F32MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16003 { AUDIO_F32MSB, 6, 1, 0, SDL_Upsample_F32MSB_6c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16004 { AUDIO_F32MSB, 8, 0, 0, SDL_Downsample_F32MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16005 { AUDIO_F32MSB, 8, 1, 0, SDL_Upsample_F32MSB_8c },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16006 #if !LESS_RESAMPLERS
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16007 { AUDIO_U8, 1, 0, 2, SDL_Downsample_U8_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16008 { AUDIO_U8, 1, 1, 2, SDL_Upsample_U8_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16009 { AUDIO_U8, 1, 0, 4, SDL_Downsample_U8_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16010 { AUDIO_U8, 1, 1, 4, SDL_Upsample_U8_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16011 { AUDIO_U8, 2, 0, 2, SDL_Downsample_U8_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16012 { AUDIO_U8, 2, 1, 2, SDL_Upsample_U8_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16013 { AUDIO_U8, 2, 0, 4, SDL_Downsample_U8_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16014 { AUDIO_U8, 2, 1, 4, SDL_Upsample_U8_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16015 { AUDIO_U8, 4, 0, 2, SDL_Downsample_U8_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16016 { AUDIO_U8, 4, 1, 2, SDL_Upsample_U8_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16017 { AUDIO_U8, 4, 0, 4, SDL_Downsample_U8_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16018 { AUDIO_U8, 4, 1, 4, SDL_Upsample_U8_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16019 { AUDIO_U8, 6, 0, 2, SDL_Downsample_U8_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16020 { AUDIO_U8, 6, 1, 2, SDL_Upsample_U8_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16021 { AUDIO_U8, 6, 0, 4, SDL_Downsample_U8_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16022 { AUDIO_U8, 6, 1, 4, SDL_Upsample_U8_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16023 { AUDIO_U8, 8, 0, 2, SDL_Downsample_U8_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16024 { AUDIO_U8, 8, 1, 2, SDL_Upsample_U8_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16025 { AUDIO_U8, 8, 0, 4, SDL_Downsample_U8_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16026 { AUDIO_U8, 8, 1, 4, SDL_Upsample_U8_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16027 { AUDIO_S8, 1, 0, 2, SDL_Downsample_S8_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16028 { AUDIO_S8, 1, 1, 2, SDL_Upsample_S8_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16029 { AUDIO_S8, 1, 0, 4, SDL_Downsample_S8_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16030 { AUDIO_S8, 1, 1, 4, SDL_Upsample_S8_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16031 { AUDIO_S8, 2, 0, 2, SDL_Downsample_S8_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16032 { AUDIO_S8, 2, 1, 2, SDL_Upsample_S8_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16033 { AUDIO_S8, 2, 0, 4, SDL_Downsample_S8_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16034 { AUDIO_S8, 2, 1, 4, SDL_Upsample_S8_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16035 { AUDIO_S8, 4, 0, 2, SDL_Downsample_S8_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16036 { AUDIO_S8, 4, 1, 2, SDL_Upsample_S8_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16037 { AUDIO_S8, 4, 0, 4, SDL_Downsample_S8_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16038 { AUDIO_S8, 4, 1, 4, SDL_Upsample_S8_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16039 { AUDIO_S8, 6, 0, 2, SDL_Downsample_S8_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16040 { AUDIO_S8, 6, 1, 2, SDL_Upsample_S8_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16041 { AUDIO_S8, 6, 0, 4, SDL_Downsample_S8_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16042 { AUDIO_S8, 6, 1, 4, SDL_Upsample_S8_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16043 { AUDIO_S8, 8, 0, 2, SDL_Downsample_S8_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16044 { AUDIO_S8, 8, 1, 2, SDL_Upsample_S8_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16045 { AUDIO_S8, 8, 0, 4, SDL_Downsample_S8_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16046 { AUDIO_S8, 8, 1, 4, SDL_Upsample_S8_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16047 { AUDIO_U16LSB, 1, 0, 2, SDL_Downsample_U16LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16048 { AUDIO_U16LSB, 1, 1, 2, SDL_Upsample_U16LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16049 { AUDIO_U16LSB, 1, 0, 4, SDL_Downsample_U16LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16050 { AUDIO_U16LSB, 1, 1, 4, SDL_Upsample_U16LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16051 { AUDIO_U16LSB, 2, 0, 2, SDL_Downsample_U16LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16052 { AUDIO_U16LSB, 2, 1, 2, SDL_Upsample_U16LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16053 { AUDIO_U16LSB, 2, 0, 4, SDL_Downsample_U16LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16054 { AUDIO_U16LSB, 2, 1, 4, SDL_Upsample_U16LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16055 { AUDIO_U16LSB, 4, 0, 2, SDL_Downsample_U16LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16056 { AUDIO_U16LSB, 4, 1, 2, SDL_Upsample_U16LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16057 { AUDIO_U16LSB, 4, 0, 4, SDL_Downsample_U16LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16058 { AUDIO_U16LSB, 4, 1, 4, SDL_Upsample_U16LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16059 { AUDIO_U16LSB, 6, 0, 2, SDL_Downsample_U16LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16060 { AUDIO_U16LSB, 6, 1, 2, SDL_Upsample_U16LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16061 { AUDIO_U16LSB, 6, 0, 4, SDL_Downsample_U16LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16062 { AUDIO_U16LSB, 6, 1, 4, SDL_Upsample_U16LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16063 { AUDIO_U16LSB, 8, 0, 2, SDL_Downsample_U16LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16064 { AUDIO_U16LSB, 8, 1, 2, SDL_Upsample_U16LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16065 { AUDIO_U16LSB, 8, 0, 4, SDL_Downsample_U16LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16066 { AUDIO_U16LSB, 8, 1, 4, SDL_Upsample_U16LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16067 { AUDIO_S16LSB, 1, 0, 2, SDL_Downsample_S16LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16068 { AUDIO_S16LSB, 1, 1, 2, SDL_Upsample_S16LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16069 { AUDIO_S16LSB, 1, 0, 4, SDL_Downsample_S16LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16070 { AUDIO_S16LSB, 1, 1, 4, SDL_Upsample_S16LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16071 { AUDIO_S16LSB, 2, 0, 2, SDL_Downsample_S16LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16072 { AUDIO_S16LSB, 2, 1, 2, SDL_Upsample_S16LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16073 { AUDIO_S16LSB, 2, 0, 4, SDL_Downsample_S16LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16074 { AUDIO_S16LSB, 2, 1, 4, SDL_Upsample_S16LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16075 { AUDIO_S16LSB, 4, 0, 2, SDL_Downsample_S16LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16076 { AUDIO_S16LSB, 4, 1, 2, SDL_Upsample_S16LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16077 { AUDIO_S16LSB, 4, 0, 4, SDL_Downsample_S16LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16078 { AUDIO_S16LSB, 4, 1, 4, SDL_Upsample_S16LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16079 { AUDIO_S16LSB, 6, 0, 2, SDL_Downsample_S16LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16080 { AUDIO_S16LSB, 6, 1, 2, SDL_Upsample_S16LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16081 { AUDIO_S16LSB, 6, 0, 4, SDL_Downsample_S16LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16082 { AUDIO_S16LSB, 6, 1, 4, SDL_Upsample_S16LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16083 { AUDIO_S16LSB, 8, 0, 2, SDL_Downsample_S16LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16084 { AUDIO_S16LSB, 8, 1, 2, SDL_Upsample_S16LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16085 { AUDIO_S16LSB, 8, 0, 4, SDL_Downsample_S16LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16086 { AUDIO_S16LSB, 8, 1, 4, SDL_Upsample_S16LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16087 { AUDIO_U16MSB, 1, 0, 2, SDL_Downsample_U16MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16088 { AUDIO_U16MSB, 1, 1, 2, SDL_Upsample_U16MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16089 { AUDIO_U16MSB, 1, 0, 4, SDL_Downsample_U16MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16090 { AUDIO_U16MSB, 1, 1, 4, SDL_Upsample_U16MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16091 { AUDIO_U16MSB, 2, 0, 2, SDL_Downsample_U16MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16092 { AUDIO_U16MSB, 2, 1, 2, SDL_Upsample_U16MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16093 { AUDIO_U16MSB, 2, 0, 4, SDL_Downsample_U16MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16094 { AUDIO_U16MSB, 2, 1, 4, SDL_Upsample_U16MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16095 { AUDIO_U16MSB, 4, 0, 2, SDL_Downsample_U16MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16096 { AUDIO_U16MSB, 4, 1, 2, SDL_Upsample_U16MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16097 { AUDIO_U16MSB, 4, 0, 4, SDL_Downsample_U16MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16098 { AUDIO_U16MSB, 4, 1, 4, SDL_Upsample_U16MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16099 { AUDIO_U16MSB, 6, 0, 2, SDL_Downsample_U16MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16100 { AUDIO_U16MSB, 6, 1, 2, SDL_Upsample_U16MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16101 { AUDIO_U16MSB, 6, 0, 4, SDL_Downsample_U16MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16102 { AUDIO_U16MSB, 6, 1, 4, SDL_Upsample_U16MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16103 { AUDIO_U16MSB, 8, 0, 2, SDL_Downsample_U16MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16104 { AUDIO_U16MSB, 8, 1, 2, SDL_Upsample_U16MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16105 { AUDIO_U16MSB, 8, 0, 4, SDL_Downsample_U16MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16106 { AUDIO_U16MSB, 8, 1, 4, SDL_Upsample_U16MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16107 { AUDIO_S16MSB, 1, 0, 2, SDL_Downsample_S16MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16108 { AUDIO_S16MSB, 1, 1, 2, SDL_Upsample_S16MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16109 { AUDIO_S16MSB, 1, 0, 4, SDL_Downsample_S16MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16110 { AUDIO_S16MSB, 1, 1, 4, SDL_Upsample_S16MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16111 { AUDIO_S16MSB, 2, 0, 2, SDL_Downsample_S16MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16112 { AUDIO_S16MSB, 2, 1, 2, SDL_Upsample_S16MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16113 { AUDIO_S16MSB, 2, 0, 4, SDL_Downsample_S16MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16114 { AUDIO_S16MSB, 2, 1, 4, SDL_Upsample_S16MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16115 { AUDIO_S16MSB, 4, 0, 2, SDL_Downsample_S16MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16116 { AUDIO_S16MSB, 4, 1, 2, SDL_Upsample_S16MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16117 { AUDIO_S16MSB, 4, 0, 4, SDL_Downsample_S16MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16118 { AUDIO_S16MSB, 4, 1, 4, SDL_Upsample_S16MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16119 { AUDIO_S16MSB, 6, 0, 2, SDL_Downsample_S16MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16120 { AUDIO_S16MSB, 6, 1, 2, SDL_Upsample_S16MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16121 { AUDIO_S16MSB, 6, 0, 4, SDL_Downsample_S16MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16122 { AUDIO_S16MSB, 6, 1, 4, SDL_Upsample_S16MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16123 { AUDIO_S16MSB, 8, 0, 2, SDL_Downsample_S16MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16124 { AUDIO_S16MSB, 8, 1, 2, SDL_Upsample_S16MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16125 { AUDIO_S16MSB, 8, 0, 4, SDL_Downsample_S16MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16126 { AUDIO_S16MSB, 8, 1, 4, SDL_Upsample_S16MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16127 { AUDIO_S32LSB, 1, 0, 2, SDL_Downsample_S32LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16128 { AUDIO_S32LSB, 1, 1, 2, SDL_Upsample_S32LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16129 { AUDIO_S32LSB, 1, 0, 4, SDL_Downsample_S32LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16130 { AUDIO_S32LSB, 1, 1, 4, SDL_Upsample_S32LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16131 { AUDIO_S32LSB, 2, 0, 2, SDL_Downsample_S32LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16132 { AUDIO_S32LSB, 2, 1, 2, SDL_Upsample_S32LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16133 { AUDIO_S32LSB, 2, 0, 4, SDL_Downsample_S32LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16134 { AUDIO_S32LSB, 2, 1, 4, SDL_Upsample_S32LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16135 { AUDIO_S32LSB, 4, 0, 2, SDL_Downsample_S32LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16136 { AUDIO_S32LSB, 4, 1, 2, SDL_Upsample_S32LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16137 { AUDIO_S32LSB, 4, 0, 4, SDL_Downsample_S32LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16138 { AUDIO_S32LSB, 4, 1, 4, SDL_Upsample_S32LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16139 { AUDIO_S32LSB, 6, 0, 2, SDL_Downsample_S32LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16140 { AUDIO_S32LSB, 6, 1, 2, SDL_Upsample_S32LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16141 { AUDIO_S32LSB, 6, 0, 4, SDL_Downsample_S32LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16142 { AUDIO_S32LSB, 6, 1, 4, SDL_Upsample_S32LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16143 { AUDIO_S32LSB, 8, 0, 2, SDL_Downsample_S32LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16144 { AUDIO_S32LSB, 8, 1, 2, SDL_Upsample_S32LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16145 { AUDIO_S32LSB, 8, 0, 4, SDL_Downsample_S32LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16146 { AUDIO_S32LSB, 8, 1, 4, SDL_Upsample_S32LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16147 { AUDIO_S32MSB, 1, 0, 2, SDL_Downsample_S32MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16148 { AUDIO_S32MSB, 1, 1, 2, SDL_Upsample_S32MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16149 { AUDIO_S32MSB, 1, 0, 4, SDL_Downsample_S32MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16150 { AUDIO_S32MSB, 1, 1, 4, SDL_Upsample_S32MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16151 { AUDIO_S32MSB, 2, 0, 2, SDL_Downsample_S32MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16152 { AUDIO_S32MSB, 2, 1, 2, SDL_Upsample_S32MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16153 { AUDIO_S32MSB, 2, 0, 4, SDL_Downsample_S32MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16154 { AUDIO_S32MSB, 2, 1, 4, SDL_Upsample_S32MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16155 { AUDIO_S32MSB, 4, 0, 2, SDL_Downsample_S32MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16156 { AUDIO_S32MSB, 4, 1, 2, SDL_Upsample_S32MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16157 { AUDIO_S32MSB, 4, 0, 4, SDL_Downsample_S32MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16158 { AUDIO_S32MSB, 4, 1, 4, SDL_Upsample_S32MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16159 { AUDIO_S32MSB, 6, 0, 2, SDL_Downsample_S32MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16160 { AUDIO_S32MSB, 6, 1, 2, SDL_Upsample_S32MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16161 { AUDIO_S32MSB, 6, 0, 4, SDL_Downsample_S32MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16162 { AUDIO_S32MSB, 6, 1, 4, SDL_Upsample_S32MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16163 { AUDIO_S32MSB, 8, 0, 2, SDL_Downsample_S32MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16164 { AUDIO_S32MSB, 8, 1, 2, SDL_Upsample_S32MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16165 { AUDIO_S32MSB, 8, 0, 4, SDL_Downsample_S32MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16166 { AUDIO_S32MSB, 8, 1, 4, SDL_Upsample_S32MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16167 { AUDIO_F32LSB, 1, 0, 2, SDL_Downsample_F32LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16168 { AUDIO_F32LSB, 1, 1, 2, SDL_Upsample_F32LSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16169 { AUDIO_F32LSB, 1, 0, 4, SDL_Downsample_F32LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16170 { AUDIO_F32LSB, 1, 1, 4, SDL_Upsample_F32LSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16171 { AUDIO_F32LSB, 2, 0, 2, SDL_Downsample_F32LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16172 { AUDIO_F32LSB, 2, 1, 2, SDL_Upsample_F32LSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16173 { AUDIO_F32LSB, 2, 0, 4, SDL_Downsample_F32LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16174 { AUDIO_F32LSB, 2, 1, 4, SDL_Upsample_F32LSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16175 { AUDIO_F32LSB, 4, 0, 2, SDL_Downsample_F32LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16176 { AUDIO_F32LSB, 4, 1, 2, SDL_Upsample_F32LSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16177 { AUDIO_F32LSB, 4, 0, 4, SDL_Downsample_F32LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16178 { AUDIO_F32LSB, 4, 1, 4, SDL_Upsample_F32LSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16179 { AUDIO_F32LSB, 6, 0, 2, SDL_Downsample_F32LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16180 { AUDIO_F32LSB, 6, 1, 2, SDL_Upsample_F32LSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16181 { AUDIO_F32LSB, 6, 0, 4, SDL_Downsample_F32LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16182 { AUDIO_F32LSB, 6, 1, 4, SDL_Upsample_F32LSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16183 { AUDIO_F32LSB, 8, 0, 2, SDL_Downsample_F32LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16184 { AUDIO_F32LSB, 8, 1, 2, SDL_Upsample_F32LSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16185 { AUDIO_F32LSB, 8, 0, 4, SDL_Downsample_F32LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16186 { AUDIO_F32LSB, 8, 1, 4, SDL_Upsample_F32LSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16187 { AUDIO_F32MSB, 1, 0, 2, SDL_Downsample_F32MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16188 { AUDIO_F32MSB, 1, 1, 2, SDL_Upsample_F32MSB_1c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16189 { AUDIO_F32MSB, 1, 0, 4, SDL_Downsample_F32MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16190 { AUDIO_F32MSB, 1, 1, 4, SDL_Upsample_F32MSB_1c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16191 { AUDIO_F32MSB, 2, 0, 2, SDL_Downsample_F32MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16192 { AUDIO_F32MSB, 2, 1, 2, SDL_Upsample_F32MSB_2c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16193 { AUDIO_F32MSB, 2, 0, 4, SDL_Downsample_F32MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16194 { AUDIO_F32MSB, 2, 1, 4, SDL_Upsample_F32MSB_2c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16195 { AUDIO_F32MSB, 4, 0, 2, SDL_Downsample_F32MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16196 { AUDIO_F32MSB, 4, 1, 2, SDL_Upsample_F32MSB_4c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16197 { AUDIO_F32MSB, 4, 0, 4, SDL_Downsample_F32MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16198 { AUDIO_F32MSB, 4, 1, 4, SDL_Upsample_F32MSB_4c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16199 { AUDIO_F32MSB, 6, 0, 2, SDL_Downsample_F32MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16200 { AUDIO_F32MSB, 6, 1, 2, SDL_Upsample_F32MSB_6c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16201 { AUDIO_F32MSB, 6, 0, 4, SDL_Downsample_F32MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16202 { AUDIO_F32MSB, 6, 1, 4, SDL_Upsample_F32MSB_6c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16203 { AUDIO_F32MSB, 8, 0, 2, SDL_Downsample_F32MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16204 { AUDIO_F32MSB, 8, 1, 2, SDL_Upsample_F32MSB_8c_x2 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16205 { AUDIO_F32MSB, 8, 0, 4, SDL_Downsample_F32MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16206 { AUDIO_F32MSB, 8, 1, 4, SDL_Upsample_F32MSB_8c_x4 },
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16207 #endif /* !LESS_RESAMPLERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16208 #endif /* !NO_RESAMPLERS */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16209 { 0, 0, 0, 0, NULL }
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16210 };
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16211
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16212 /* 390 converters generated. */
f3dcf04412cf First shot at new audio resampling code.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
16213
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
16214 /* *INDENT-ON* */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
16215
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
16216 /* vi: set ts=4 sw=4 expandtab: */