Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audiocvt.c @ 2728:2768bd7281e0
Fixed Visual Studio compilation problems
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 26 Aug 2008 07:34:49 +0000 |
parents | f8f68f47285a |
children | 79c1bd651f04 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1011
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
22 #include "SDL_config.h" |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
23 |
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
24 #define _USE_MATH_DEFINES |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
25 #include <math.h> |
0 | 26 |
27 /* Functions for audio drivers to perform runtime conversion of audio format */ | |
28 | |
29 #include "SDL_audio.h" | |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
30 #include "SDL_audio_c.h" |
0 | 31 |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
32 //#define DEBUG_CONVERT |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
33 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
34 /* These are fractional multiplication routines. That is, their inputs |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
35 are two numbers in the range [-1, 1) and the result falls in that |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
36 same range. The output is the same size as the inputs, i.e. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
37 32-bit x 32-bit = 32-bit. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
38 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
39 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
40 /* We hope here that the right shift includes sign extension */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
41 #ifdef SDL_HAS_64BIT_Type |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
42 #define SDL_FixMpy32(a, b) ((((Sint64)a * (Sint64)b) >> 31) & 0xffffffff) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
43 #else |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
44 /* If we don't have the 64-bit type, do something more complicated. See http://www.8052.com/mul16.phtml or http://www.cs.uaf.edu/~cs301/notes/Chapter5/node5.html */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
45 #define SDL_FixMpy32(a, b) ((((Sint64)a * (Sint64)b) >> 31) & 0xffffffff) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
46 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
47 #define SDL_FixMpy16(a, b) ((((Sint32)a * (Sint32)b) >> 14) & 0xffff) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
48 #define SDL_FixMpy8(a, b) ((((Sint16)a * (Sint16)b) >> 7) & 0xff) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
49 /* This macro just makes the floating point filtering code not have to be a special case. */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
50 #define SDL_FloatMpy(a, b) (a * b) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
51 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
52 /* These macros take floating point numbers in the range [-1.0f, 1.0f) and |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
53 represent them as fixed-point numbers in that same range. There's no |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
54 checking that the floating point argument is inside the appropriate range. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
55 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
56 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
57 #define SDL_Make_1_7(a) (Sint8)(a * 128.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
58 #define SDL_Make_1_15(a) (Sint16)(a * 32768.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
59 #define SDL_Make_1_31(a) (Sint32)(a * 2147483648.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
60 #define SDL_Make_2_6(a) (Sint8)(a * 64.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
61 #define SDL_Make_2_14(a) (Sint16)(a * 16384.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
62 #define SDL_Make_2_30(a) (Sint32)(a * 1073741824.0f) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
63 |
0 | 64 /* Effectively mix right and left channels into a single channel */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
65 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
66 SDL_ConvertMono(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
0 | 67 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
68 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
69 Sint32 sample; |
0 | 70 |
71 #ifdef DEBUG_CONVERT | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
72 fprintf(stderr, "Converting to mono\n"); |
0 | 73 #endif |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
74 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
75 case AUDIO_U8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
76 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
77 Uint8 *src, *dst; |
0 | 78 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
79 src = cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
80 dst = cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
81 for (i = cvt->len_cvt / 2; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
82 sample = src[0] + src[1]; |
2042 | 83 *dst = (Uint8) (sample / 2); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
84 src += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
85 dst += 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
86 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
87 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
88 break; |
0 | 89 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
90 case AUDIO_S8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
91 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
92 Sint8 *src, *dst; |
0 | 93 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
94 src = (Sint8 *) cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
95 dst = (Sint8 *) cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
96 for (i = cvt->len_cvt / 2; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
97 sample = src[0] + src[1]; |
2042 | 98 *dst = (Sint8) (sample / 2); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
99 src += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
100 dst += 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
101 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
102 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
103 break; |
0 | 104 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
105 case AUDIO_U16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
106 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
107 Uint8 *src, *dst; |
0 | 108 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
109 src = cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
110 dst = cvt->buf; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
111 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
112 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
113 sample = (Uint16) ((src[0] << 8) | src[1]) + |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
114 (Uint16) ((src[2] << 8) | src[3]); |
2042 | 115 sample /= 2; |
116 dst[1] = (sample & 0xFF); | |
117 sample >>= 8; | |
118 dst[0] = (sample & 0xFF); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
119 src += 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
120 dst += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
121 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
122 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
123 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
124 sample = (Uint16) ((src[1] << 8) | src[0]) + |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
125 (Uint16) ((src[3] << 8) | src[2]); |
2042 | 126 sample /= 2; |
127 dst[0] = (sample & 0xFF); | |
128 sample >>= 8; | |
129 dst[1] = (sample & 0xFF); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
130 src += 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
131 dst += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
132 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
133 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
134 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
135 break; |
0 | 136 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
137 case AUDIO_S16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
138 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
139 Uint8 *src, *dst; |
0 | 140 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
141 src = cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
142 dst = cvt->buf; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
143 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
144 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
145 sample = (Sint16) ((src[0] << 8) | src[1]) + |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
146 (Sint16) ((src[2] << 8) | src[3]); |
2042 | 147 sample /= 2; |
148 dst[1] = (sample & 0xFF); | |
149 sample >>= 8; | |
150 dst[0] = (sample & 0xFF); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
151 src += 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
152 dst += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
153 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
154 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
155 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
156 sample = (Sint16) ((src[1] << 8) | src[0]) + |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
157 (Sint16) ((src[3] << 8) | src[2]); |
2042 | 158 sample /= 2; |
159 dst[0] = (sample & 0xFF); | |
160 sample >>= 8; | |
161 dst[1] = (sample & 0xFF); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
162 src += 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
163 dst += 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
164 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
165 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
166 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
167 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
168 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
169 case AUDIO_S32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
170 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
171 const Uint32 *src = (const Uint32 *) cvt->buf; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
172 Uint32 *dst = (Uint32 *) cvt->buf; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
173 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
174 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
175 const Sint64 added = |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
176 (((Sint64) (Sint32) SDL_SwapBE32(src[0])) + |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
177 ((Sint64) (Sint32) SDL_SwapBE32(src[1]))); |
2078
f932ac47a331
Apparently it's possible that MSVC will want to call a built-in function to
Ryan C. Gordon <icculus@icculus.org>
parents:
2049
diff
changeset
|
178 *(dst++) = SDL_SwapBE32((Uint32) ((Sint32) (added / 2))); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
179 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
180 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
181 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
182 const Sint64 added = |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
183 (((Sint64) (Sint32) SDL_SwapLE32(src[0])) + |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
184 ((Sint64) (Sint32) SDL_SwapLE32(src[1]))); |
2078
f932ac47a331
Apparently it's possible that MSVC will want to call a built-in function to
Ryan C. Gordon <icculus@icculus.org>
parents:
2049
diff
changeset
|
185 *(dst++) = SDL_SwapLE32((Uint32) ((Sint32) (added / 2))); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
186 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
187 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
188 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
189 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
190 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
191 case AUDIO_F32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
192 { |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
193 const float *src = (const float *) cvt->buf; |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
194 float *dst = (float *) cvt->buf; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
195 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
196 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
197 const float src1 = SDL_SwapFloatBE(src[0]); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
198 const float src2 = SDL_SwapFloatBE(src[1]); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
199 const double added = ((double) src1) + ((double) src2); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
200 const float halved = (float) (added * 0.5); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
201 *(dst++) = SDL_SwapFloatBE(halved); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
202 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
203 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
204 for (i = cvt->len_cvt / 8; i; --i, src += 2) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
205 const float src1 = SDL_SwapFloatLE(src[0]); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
206 const float src2 = SDL_SwapFloatLE(src[1]); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
207 const double added = ((double) src1) + ((double) src2); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
208 const float halved = (float) (added * 0.5); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2042
diff
changeset
|
209 *(dst++) = SDL_SwapFloatLE(halved); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
210 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
211 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
212 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
213 break; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
214 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
215 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
216 cvt->len_cvt /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
217 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
218 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
219 } |
0 | 220 } |
221 | |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
222 |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
223 /* Discard top 4 channels */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
224 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
225 SDL_ConvertStrip(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
226 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
227 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
228 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
229 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
230 fprintf(stderr, "Converting down from 6 channels to stereo\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
231 #endif |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
232 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
233 #define strip_chans_6_to_2(type) \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
234 { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
235 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
236 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
237 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
238 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
239 dst[1] = src[1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
240 src += 6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
241 dst += 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
242 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
243 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
244 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
245 /* this function only cares about typesize, and data as a block of bits. */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
246 switch (SDL_AUDIO_BITSIZE(format)) { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
247 case 8: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
248 strip_chans_6_to_2(Uint8); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
249 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
250 case 16: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
251 strip_chans_6_to_2(Uint16); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
252 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
253 case 32: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
254 strip_chans_6_to_2(Uint32); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
255 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
256 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
257 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
258 #undef strip_chans_6_to_2 |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
259 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
260 cvt->len_cvt /= 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
261 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
262 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
263 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
264 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
265 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
266 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
267 /* Discard top 2 channels of 6 */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
268 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
269 SDL_ConvertStrip_2(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
270 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
271 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
272 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
273 #ifdef DEBUG_CONVERT |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
274 fprintf(stderr, "Converting 6 down to quad\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
275 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
276 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
277 #define strip_chans_6_to_4(type) \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
278 { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
279 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
280 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
281 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
282 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
283 dst[1] = src[1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
284 dst[2] = src[2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
285 dst[3] = src[3]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
286 src += 6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
287 dst += 4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
288 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
289 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
290 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
291 /* this function only cares about typesize, and data as a block of bits. */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
292 switch (SDL_AUDIO_BITSIZE(format)) { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
293 case 8: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
294 strip_chans_6_to_4(Uint8); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
295 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
296 case 16: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
297 strip_chans_6_to_4(Uint16); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
298 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
299 case 32: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
300 strip_chans_6_to_4(Uint32); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
301 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
302 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
303 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
304 #undef strip_chans_6_to_4 |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
305 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
306 cvt->len_cvt /= 6; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
307 cvt->len_cvt *= 4; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
308 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
309 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
310 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
311 } |
0 | 312 |
313 /* Duplicate a mono channel to both stereo channels */ | |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
314 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
315 SDL_ConvertStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
0 | 316 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
317 int i; |
0 | 318 |
319 #ifdef DEBUG_CONVERT | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
320 fprintf(stderr, "Converting to stereo\n"); |
0 | 321 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
322 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
323 #define dup_chans_1_to_2(type) \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
324 { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
325 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
326 type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
327 for (i = cvt->len_cvt / 2; i; --i, --src) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
328 const type val = *src; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
329 dst -= 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
330 dst[0] = dst[1] = val; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
331 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
332 } |
0 | 333 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
334 /* this function only cares about typesize, and data as a block of bits. */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
335 switch (SDL_AUDIO_BITSIZE(format)) { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
336 case 8: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
337 dup_chans_1_to_2(Uint8); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
338 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
339 case 16: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
340 dup_chans_1_to_2(Uint16); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
341 break; |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
342 case 32: |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
343 dup_chans_1_to_2(Uint32); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
344 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
345 } |
0 | 346 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
347 #undef dup_chans_1_to_2 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
348 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
349 cvt->len_cvt *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
350 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
351 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
352 } |
0 | 353 } |
354 | |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
355 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
356 /* Duplicate a stereo channel to a pseudo-5.1 stream */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
357 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
358 SDL_ConvertSurround(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
359 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
360 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
361 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
362 #ifdef DEBUG_CONVERT |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
363 fprintf(stderr, "Converting stereo to surround\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
364 #endif |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
365 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
366 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
367 case AUDIO_U8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
368 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
369 Uint8 *src, *dst, lf, rf, ce; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
370 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
371 src = (Uint8 *) (cvt->buf + cvt->len_cvt); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
372 dst = (Uint8 *) (cvt->buf + cvt->len_cvt * 3); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
373 for (i = cvt->len_cvt; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
374 dst -= 6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
375 src -= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
376 lf = src[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
377 rf = src[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
378 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
379 dst[0] = lf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
380 dst[1] = rf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
381 dst[2] = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
382 dst[3] = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
383 dst[4] = ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
384 dst[5] = ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
385 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
386 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
387 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
388 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
389 case AUDIO_S8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
390 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
391 Sint8 *src, *dst, lf, rf, ce; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
392 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
393 src = (Sint8 *) cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
394 dst = (Sint8 *) cvt->buf + cvt->len_cvt * 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
395 for (i = cvt->len_cvt; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
396 dst -= 6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
397 src -= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
398 lf = src[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
399 rf = src[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
400 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
401 dst[0] = lf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
402 dst[1] = rf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
403 dst[2] = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
404 dst[3] = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
405 dst[4] = ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
406 dst[5] = ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
407 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
408 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
409 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
410 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
411 case AUDIO_U16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
412 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
413 Uint8 *src, *dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
414 Uint16 lf, rf, ce, lr, rr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
415 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
416 src = cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
417 dst = cvt->buf + cvt->len_cvt * 3; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
418 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
419 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
420 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
421 dst -= 12; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
422 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
423 lf = (Uint16) ((src[0] << 8) | src[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
424 rf = (Uint16) ((src[2] << 8) | src[3]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
425 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
426 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
427 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
428 dst[1] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
429 dst[0] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
430 dst[3] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
431 dst[2] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
432 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
433 dst[1 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
434 dst[0 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
435 dst[3 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
436 dst[2 + 4] = ((rr >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
437 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
438 dst[1 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
439 dst[0 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
440 dst[3 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
441 dst[2 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
442 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
443 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
444 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
445 dst -= 12; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
446 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
447 lf = (Uint16) ((src[1] << 8) | src[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
448 rf = (Uint16) ((src[3] << 8) | src[2]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
449 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
450 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
451 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
452 dst[0] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
453 dst[1] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
454 dst[2] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
455 dst[3] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
456 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
457 dst[0 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
458 dst[1 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
459 dst[2 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
460 dst[3 + 4] = ((rr >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
461 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
462 dst[0 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
463 dst[1 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
464 dst[2 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
465 dst[3 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
466 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
467 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
468 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
469 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
470 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
471 case AUDIO_S16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
472 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
473 Uint8 *src, *dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
474 Sint16 lf, rf, ce, lr, rr; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
475 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
476 src = cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
477 dst = cvt->buf + cvt->len_cvt * 3; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
478 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
479 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
480 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
481 dst -= 12; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
482 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
483 lf = (Sint16) ((src[0] << 8) | src[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
484 rf = (Sint16) ((src[2] << 8) | src[3]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
485 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
486 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
487 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
488 dst[1] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
489 dst[0] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
490 dst[3] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
491 dst[2] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
492 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
493 dst[1 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
494 dst[0 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
495 dst[3 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
496 dst[2 + 4] = ((rr >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
497 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
498 dst[1 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
499 dst[0 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
500 dst[3 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
501 dst[2 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
502 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
503 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
504 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
505 dst -= 12; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
506 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
507 lf = (Sint16) ((src[1] << 8) | src[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
508 rf = (Sint16) ((src[3] << 8) | src[2]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
509 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
510 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
511 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
512 dst[0] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
513 dst[1] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
514 dst[2] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
515 dst[3] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
516 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
517 dst[0 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
518 dst[1 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
519 dst[2 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
520 dst[3 + 4] = ((rr >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
521 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
522 dst[0 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
523 dst[1 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
524 dst[2 + 8] = (ce & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
525 dst[3 + 8] = ((ce >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
526 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
527 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
528 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
529 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
530 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
531 case AUDIO_S32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
532 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
533 Sint32 lf, rf, ce; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
534 const Uint32 *src = (const Uint32 *) cvt->buf + cvt->len_cvt; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
535 Uint32 *dst = (Uint32 *) cvt->buf + cvt->len_cvt * 3; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
536 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
537 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
538 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
539 dst -= 6; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
540 src -= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
541 lf = (Sint32) SDL_SwapBE32(src[0]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
542 rf = (Sint32) SDL_SwapBE32(src[1]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
543 ce = (lf / 2) + (rf / 2); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
544 dst[0] = SDL_SwapBE32((Uint32) lf); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
545 dst[1] = SDL_SwapBE32((Uint32) rf); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
546 dst[2] = SDL_SwapBE32((Uint32) (lf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
547 dst[3] = SDL_SwapBE32((Uint32) (rf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
548 dst[4] = SDL_SwapBE32((Uint32) ce); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
549 dst[5] = SDL_SwapBE32((Uint32) ce); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
550 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
551 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
552 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
553 dst -= 6; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
554 src -= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
555 lf = (Sint32) SDL_SwapLE32(src[0]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
556 rf = (Sint32) SDL_SwapLE32(src[1]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
557 ce = (lf / 2) + (rf / 2); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
558 dst[0] = src[0]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
559 dst[1] = src[1]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
560 dst[2] = SDL_SwapLE32((Uint32) (lf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
561 dst[3] = SDL_SwapLE32((Uint32) (rf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
562 dst[4] = SDL_SwapLE32((Uint32) ce); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
563 dst[5] = SDL_SwapLE32((Uint32) ce); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
564 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
565 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
566 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
567 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
568 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
569 case AUDIO_F32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
570 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
571 float lf, rf, ce; |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
572 const float *src = (const float *) cvt->buf + cvt->len_cvt; |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
573 float *dst = (float *) cvt->buf + cvt->len_cvt * 3; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
574 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
575 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
576 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
577 dst -= 6; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
578 src -= 2; |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
579 lf = SDL_SwapFloatBE(src[0]); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
580 rf = SDL_SwapFloatBE(src[1]); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
581 ce = (lf * 0.5f) + (rf * 0.5f); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
582 dst[0] = src[0]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
583 dst[1] = src[1]; |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
584 dst[2] = SDL_SwapFloatBE(lf - ce); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
585 dst[3] = SDL_SwapFloatBE(rf - ce); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
586 dst[4] = dst[5] = SDL_SwapFloatBE(ce); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
587 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
588 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
589 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
590 dst -= 6; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
591 src -= 2; |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
592 lf = SDL_SwapFloatLE(src[0]); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
593 rf = SDL_SwapFloatLE(src[1]); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
594 ce = (lf * 0.5f) + (rf * 0.5f); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
595 dst[0] = src[0]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
596 dst[1] = src[1]; |
2014
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
597 dst[2] = SDL_SwapFloatLE(lf - ce); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
598 dst[3] = SDL_SwapFloatLE(rf - ce); |
7abe37467fa5
Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
599 dst[4] = dst[5] = SDL_SwapFloatLE(ce); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
600 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
601 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
602 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
603 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
604 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
605 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
606 cvt->len_cvt *= 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
607 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
608 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
609 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
610 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
611 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
612 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
613 /* Duplicate a stereo channel to a pseudo-4.0 stream */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
614 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
615 SDL_ConvertSurround_4(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
616 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
617 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
618 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
619 #ifdef DEBUG_CONVERT |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
620 fprintf(stderr, "Converting stereo to quad\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
621 #endif |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
622 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
623 switch (format & (SDL_AUDIO_MASK_SIGNED | SDL_AUDIO_MASK_BITSIZE)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
624 case AUDIO_U8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
625 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
626 Uint8 *src, *dst, lf, rf, ce; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
627 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
628 src = (Uint8 *) (cvt->buf + cvt->len_cvt); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
629 dst = (Uint8 *) (cvt->buf + cvt->len_cvt * 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
630 for (i = cvt->len_cvt; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
631 dst -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
632 src -= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
633 lf = src[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
634 rf = src[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
635 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
636 dst[0] = lf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
637 dst[1] = rf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
638 dst[2] = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
639 dst[3] = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
640 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
641 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
642 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
643 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
644 case AUDIO_S8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
645 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
646 Sint8 *src, *dst, lf, rf, ce; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
647 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
648 src = (Sint8 *) cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
649 dst = (Sint8 *) cvt->buf + cvt->len_cvt * 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
650 for (i = cvt->len_cvt; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
651 dst -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
652 src -= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
653 lf = src[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
654 rf = src[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
655 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
656 dst[0] = lf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
657 dst[1] = rf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
658 dst[2] = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
659 dst[3] = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
660 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
661 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
662 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
663 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
664 case AUDIO_U16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
665 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
666 Uint8 *src, *dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
667 Uint16 lf, rf, ce, lr, rr; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
668 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
669 src = cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
670 dst = cvt->buf + cvt->len_cvt * 2; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
671 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
672 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
673 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
674 dst -= 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
675 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
676 lf = (Uint16) ((src[0] << 8) | src[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
677 rf = (Uint16) ((src[2] << 8) | src[3]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
678 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
679 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
680 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
681 dst[1] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
682 dst[0] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
683 dst[3] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
684 dst[2] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
685 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
686 dst[1 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
687 dst[0 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
688 dst[3 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
689 dst[2 + 4] = ((rr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
690 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
691 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
692 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
693 dst -= 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
694 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
695 lf = (Uint16) ((src[1] << 8) | src[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
696 rf = (Uint16) ((src[3] << 8) | src[2]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
697 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
698 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
699 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
700 dst[0] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
701 dst[1] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
702 dst[2] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
703 dst[3] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
704 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
705 dst[0 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
706 dst[1 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
707 dst[2 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
708 dst[3 + 4] = ((rr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
709 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
710 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
711 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
712 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
713 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
714 case AUDIO_S16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
715 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
716 Uint8 *src, *dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
717 Sint16 lf, rf, ce, lr, rr; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
718 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
719 src = cvt->buf + cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
720 dst = cvt->buf + cvt->len_cvt * 2; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
721 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
722 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
723 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
724 dst -= 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
725 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
726 lf = (Sint16) ((src[0] << 8) | src[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
727 rf = (Sint16) ((src[2] << 8) | src[3]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
728 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
729 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
730 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
731 dst[1] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
732 dst[0] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
733 dst[3] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
734 dst[2] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
735 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
736 dst[1 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
737 dst[0 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
738 dst[3 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
739 dst[2 + 4] = ((rr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
740 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
741 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
742 for (i = cvt->len_cvt / 4; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
743 dst -= 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
744 src -= 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
745 lf = (Sint16) ((src[1] << 8) | src[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
746 rf = (Sint16) ((src[3] << 8) | src[2]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
747 ce = (lf / 2) + (rf / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
748 rr = lf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
749 lr = rf - ce; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
750 dst[0] = (lf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
751 dst[1] = ((lf >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
752 dst[2] = (rf & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
753 dst[3] = ((rf >> 8) & 0xFF); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
754 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
755 dst[0 + 4] = (lr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
756 dst[1 + 4] = ((lr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
757 dst[2 + 4] = (rr & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
758 dst[3 + 4] = ((rr >> 8) & 0xFF); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
759 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
760 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
761 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
762 break; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
763 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
764 case AUDIO_S32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
765 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
766 const Uint32 *src = (const Uint32 *) (cvt->buf + cvt->len_cvt); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
767 Uint32 *dst = (Uint32 *) (cvt->buf + cvt->len_cvt * 2); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
768 Sint32 lf, rf, ce; |
0 | 769 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
770 if (SDL_AUDIO_ISBIGENDIAN(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
771 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
772 dst -= 4; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
773 src -= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
774 lf = (Sint32) SDL_SwapBE32(src[0]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
775 rf = (Sint32) SDL_SwapBE32(src[1]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
776 ce = (lf / 2) + (rf / 2); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
777 dst[0] = src[0]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
778 dst[1] = src[1]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
779 dst[2] = SDL_SwapBE32((Uint32) (lf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
780 dst[3] = SDL_SwapBE32((Uint32) (rf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
781 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
782 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
783 for (i = cvt->len_cvt / 8; i; --i) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
784 dst -= 4; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
785 src -= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
786 lf = (Sint32) SDL_SwapLE32(src[0]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
787 rf = (Sint32) SDL_SwapLE32(src[1]); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
788 ce = (lf / 2) + (rf / 2); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
789 dst[0] = src[0]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
790 dst[1] = src[1]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
791 dst[2] = SDL_SwapLE32((Uint32) (lf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
792 dst[3] = SDL_SwapLE32((Uint32) (rf - ce)); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
793 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
794 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
795 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
796 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
797 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
798 cvt->len_cvt *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
799 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
800 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
801 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
802 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
803 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
804 /* Convert rate up by multiple of 2 */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
805 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
806 SDL_RateMUL2(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
807 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
808 int i; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
809 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
810 #ifdef DEBUG_CONVERT |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
811 fprintf(stderr, "Converting audio rate * 2 (mono)\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
812 #endif |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
813 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
814 #define mul2_mono(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
815 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
816 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
817 for (i = cvt->len_cvt / sizeof (type); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
818 src--; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
819 dst[-1] = dst[-2] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
820 dst -= 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
821 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
822 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
823 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
824 switch (SDL_AUDIO_BITSIZE(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
825 case 8: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
826 mul2_mono(Uint8); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
827 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
828 case 16: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
829 mul2_mono(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
830 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
831 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
832 mul2_mono(Uint32); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
833 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
834 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
835 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
836 #undef mul2_mono |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
837 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
838 cvt->len_cvt *= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
839 if (cvt->filters[++cvt->filter_index]) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
840 cvt->filters[cvt->filter_index] (cvt, format); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
841 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
842 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
843 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
844 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
845 /* Convert rate up by multiple of 2, for stereo */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
846 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
847 SDL_RateMUL2_c2(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
848 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
849 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
850 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
851 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
852 fprintf(stderr, "Converting audio rate * 2 (stereo)\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
853 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
854 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
855 #define mul2_stereo(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
856 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
857 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
858 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
859 const type r = src[-1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
860 const type l = src[-2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
861 src -= 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
862 dst[-1] = r; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
863 dst[-2] = l; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
864 dst[-3] = r; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
865 dst[-4] = l; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
866 dst -= 4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
867 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
868 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
869 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
870 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
871 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
872 mul2_stereo(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
873 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
874 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
875 mul2_stereo(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
876 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
877 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
878 mul2_stereo(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
879 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
880 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
881 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
882 #undef mul2_stereo |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
883 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
884 cvt->len_cvt *= 2; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
885 if (cvt->filters[++cvt->filter_index]) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
886 cvt->filters[cvt->filter_index] (cvt, format); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
887 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
888 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
889 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
890 /* Convert rate up by multiple of 2, for quad */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
891 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
892 SDL_RateMUL2_c4(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
893 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
894 int i; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
895 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
896 #ifdef DEBUG_CONVERT |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
897 fprintf(stderr, "Converting audio rate * 2 (quad)\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
898 #endif |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
899 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
900 #define mul2_quad(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
901 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
902 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
903 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
904 const type c1 = src[-1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
905 const type c2 = src[-2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
906 const type c3 = src[-3]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
907 const type c4 = src[-4]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
908 src -= 4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
909 dst[-1] = c1; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
910 dst[-2] = c2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
911 dst[-3] = c3; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
912 dst[-4] = c4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
913 dst[-5] = c1; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
914 dst[-6] = c2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
915 dst[-7] = c3; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
916 dst[-8] = c4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
917 dst -= 8; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
918 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
919 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
920 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
921 switch (SDL_AUDIO_BITSIZE(format)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
922 case 8: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
923 mul2_quad(Uint8); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
924 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
925 case 16: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
926 mul2_quad(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
927 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
928 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
929 mul2_quad(Uint32); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
930 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
931 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
932 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
933 #undef mul2_quad |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
934 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
935 cvt->len_cvt *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
936 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
937 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
938 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
939 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
940 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
941 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
942 /* Convert rate up by multiple of 2, for 5.1 */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
943 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
944 SDL_RateMUL2_c6(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
945 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
946 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
947 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
948 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
949 fprintf(stderr, "Converting audio rate * 2 (six channels)\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
950 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
951 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
952 #define mul2_chansix(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
953 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
954 type *dst = (type *) (cvt->buf + (cvt->len_cvt * 2)); \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
955 for (i = cvt->len_cvt / (sizeof (type) * 6); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
956 const type c1 = src[-1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
957 const type c2 = src[-2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
958 const type c3 = src[-3]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
959 const type c4 = src[-4]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
960 const type c5 = src[-5]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
961 const type c6 = src[-6]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
962 src -= 6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
963 dst[-1] = c1; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
964 dst[-2] = c2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
965 dst[-3] = c3; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
966 dst[-4] = c4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
967 dst[-5] = c5; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
968 dst[-6] = c6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
969 dst[-7] = c1; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
970 dst[-8] = c2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
971 dst[-9] = c3; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
972 dst[-10] = c4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
973 dst[-11] = c5; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
974 dst[-12] = c6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
975 dst -= 12; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
976 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
977 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
978 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
979 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
980 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
981 mul2_chansix(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
982 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
983 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
984 mul2_chansix(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
985 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
986 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
987 mul2_chansix(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
988 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
989 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
990 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
991 #undef mul2_chansix |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
992 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
993 cvt->len_cvt *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
994 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
995 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
996 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
997 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
998 |
0 | 999 /* Convert rate down by multiple of 2 */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1000 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1001 SDL_RateDIV2(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
0 | 1002 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1003 int i; |
0 | 1004 |
1005 #ifdef DEBUG_CONVERT | |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1006 fprintf(stderr, "Converting audio rate / 2 (mono)\n"); |
0 | 1007 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1008 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1009 #define div2_mono(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1010 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1011 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1012 for (i = cvt->len_cvt / (sizeof (type) * 2); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1013 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1014 src += 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1015 dst++; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1016 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1017 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1018 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1019 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1020 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1021 div2_mono(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1022 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1023 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1024 div2_mono(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1025 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1026 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1027 div2_mono(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1028 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1029 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1030 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1031 #undef div2_mono |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1032 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1033 cvt->len_cvt /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1034 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1035 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1036 } |
0 | 1037 } |
1038 | |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1039 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1040 /* Convert rate down by multiple of 2, for stereo */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1041 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1042 SDL_RateDIV2_c2(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1043 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1044 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1045 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1046 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1047 fprintf(stderr, "Converting audio rate / 2 (stereo)\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1048 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1049 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1050 #define div2_stereo(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1051 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1052 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1053 for (i = cvt->len_cvt / (sizeof (type) * 4); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1054 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1055 dst[1] = src[1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1056 src += 4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1057 dst += 2; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1058 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1059 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1060 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1061 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1062 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1063 div2_stereo(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1064 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1065 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1066 div2_stereo(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1067 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1068 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1069 div2_stereo(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1070 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1071 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1072 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1073 #undef div2_stereo |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1074 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1075 cvt->len_cvt /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1076 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1077 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1078 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1079 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1080 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1081 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1082 /* Convert rate down by multiple of 2, for quad */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1083 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1084 SDL_RateDIV2_c4(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1085 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1086 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1087 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1088 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1089 fprintf(stderr, "Converting audio rate / 2 (quad)\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1090 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1091 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1092 #define div2_quad(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1093 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1094 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1095 for (i = cvt->len_cvt / (sizeof (type) * 8); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1096 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1097 dst[1] = src[1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1098 dst[2] = src[2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1099 dst[3] = src[3]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1100 src += 8; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1101 dst += 4; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1102 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1103 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1104 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1105 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1106 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1107 div2_quad(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1108 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1109 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1110 div2_quad(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1111 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1112 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1113 div2_quad(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1114 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1115 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1116 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1117 #undef div2_quad |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1118 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1119 cvt->len_cvt /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1120 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1121 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1122 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1123 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1124 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1125 /* Convert rate down by multiple of 2, for 5.1 */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1126 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1127 SDL_RateDIV2_c6(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1128 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1129 int i; |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1130 |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1131 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1132 fprintf(stderr, "Converting audio rate / 2 (six channels)\n"); |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1133 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1134 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1135 #define div2_chansix(type) { \ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1136 const type *src = (const type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1137 type *dst = (type *) cvt->buf; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1138 for (i = cvt->len_cvt / (sizeof (type) * 12); i; --i) { \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1139 dst[0] = src[0]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1140 dst[1] = src[1]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1141 dst[2] = src[2]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1142 dst[3] = src[3]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1143 dst[4] = src[4]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1144 dst[5] = src[5]; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1145 src += 12; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1146 dst += 6; \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1147 } \ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1148 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1149 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1150 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1151 case 8: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1152 div2_chansix(Uint8); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1153 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1154 case 16: |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1155 div2_chansix(Uint16); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1156 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1157 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1158 div2_chansix(Uint32); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1159 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1160 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1161 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1162 #undef div_chansix |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1163 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1164 cvt->len_cvt /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1165 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1166 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1167 } |
942
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1168 } |
41a59de7f2ed
Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
1169 |
0 | 1170 /* Very slow rate conversion routine */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1171 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1172 SDL_RateSLOW(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
0 | 1173 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1174 double ipos; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1175 int i, clen; |
0 | 1176 |
1177 #ifdef DEBUG_CONVERT | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1178 fprintf(stderr, "Converting audio rate * %4.4f\n", 1.0 / cvt->rate_incr); |
0 | 1179 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1180 clen = (int) ((double) cvt->len_cvt / cvt->rate_incr); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1181 if (cvt->rate_incr > 1.0) { |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1182 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1183 case 8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1184 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1185 Uint8 *output; |
0 | 1186 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1187 output = cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1188 ipos = 0.0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1189 for (i = clen; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1190 *output = cvt->buf[(int) ipos]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1191 ipos += cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1192 output += 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1193 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1194 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1195 break; |
0 | 1196 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1197 case 16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1198 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1199 Uint16 *output; |
0 | 1200 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1201 clen &= ~1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1202 output = (Uint16 *) cvt->buf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1203 ipos = 0.0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1204 for (i = clen / 2; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1205 *output = ((Uint16 *) cvt->buf)[(int) ipos]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1206 ipos += cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1207 output += 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1208 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1209 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1210 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1211 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1212 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1213 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1214 /* !!! FIXME: need 32-bit converter here! */ |
2130
3ee59c43d784
Fixes for compiling with Visual C++ 8.0 Express Edition
Sam Lantinga <slouken@libsdl.org>
parents:
2078
diff
changeset
|
1215 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1216 fprintf(stderr, "FIXME: need 32-bit converter here!\n"); |
2130
3ee59c43d784
Fixes for compiling with Visual C++ 8.0 Express Edition
Sam Lantinga <slouken@libsdl.org>
parents:
2078
diff
changeset
|
1217 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1218 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1219 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1220 } else { |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1221 switch (SDL_AUDIO_BITSIZE(format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1222 case 8: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1223 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1224 Uint8 *output; |
0 | 1225 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1226 output = cvt->buf + clen; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1227 ipos = (double) cvt->len_cvt; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1228 for (i = clen; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1229 ipos -= cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1230 output -= 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1231 *output = cvt->buf[(int) ipos]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1232 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1233 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1234 break; |
0 | 1235 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1236 case 16: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1237 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1238 Uint16 *output; |
0 | 1239 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1240 clen &= ~1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1241 output = (Uint16 *) (cvt->buf + clen); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1242 ipos = (double) cvt->len_cvt / 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1243 for (i = clen / 2; i; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1244 ipos -= cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1245 output -= 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1246 *output = ((Uint16 *) cvt->buf)[(int) ipos]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1247 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1248 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1249 break; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1250 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1251 case 32: |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1252 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1253 /* !!! FIXME: need 32-bit converter here! */ |
2130
3ee59c43d784
Fixes for compiling with Visual C++ 8.0 Express Edition
Sam Lantinga <slouken@libsdl.org>
parents:
2078
diff
changeset
|
1254 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1255 fprintf(stderr, "FIXME: need 32-bit converter here!\n"); |
2130
3ee59c43d784
Fixes for compiling with Visual C++ 8.0 Express Edition
Sam Lantinga <slouken@libsdl.org>
parents:
2078
diff
changeset
|
1256 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1257 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1258 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1259 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1260 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1261 cvt->len_cvt = clen; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1262 if (cvt->filters[++cvt->filter_index]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1263 cvt->filters[cvt->filter_index] (cvt, format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1264 } |
0 | 1265 } |
1266 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1267 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1268 SDL_ConvertAudio(SDL_AudioCVT * cvt) |
0 | 1269 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1270 /* Make sure there's data to convert */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1271 if (cvt->buf == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1272 SDL_SetError("No buffer allocated for conversion"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1273 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1274 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1275 /* Return okay if no conversion is necessary */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1276 cvt->len_cvt = cvt->len; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1277 if (cvt->filters[0] == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1278 return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1279 } |
0 | 1280 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1281 /* Set up the conversion and go! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1282 cvt->filter_index = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1283 cvt->filters[0] (cvt, cvt->src_format); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1284 return (0); |
0 | 1285 } |
1286 | |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1287 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1288 static SDL_AudioFilter |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1289 SDL_HandTunedTypeCVT(SDL_AudioFormat src_fmt, SDL_AudioFormat dst_fmt) |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1290 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1291 /* |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1292 * Fill in any future conversions that are specialized to a |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1293 * processor, platform, compiler, or library here. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1294 */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1295 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1296 return NULL; /* no specialized converter code available. */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1297 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1298 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1299 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1300 /* |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1301 * Find a converter between two data types. We try to select a hand-tuned |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1302 * asm/vectorized/optimized function first, and then fallback to an |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1303 * autogenerated function that is customized to convert between two |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1304 * specific data types. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1305 */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1306 static int |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1307 SDL_BuildAudioTypeCVT(SDL_AudioCVT * cvt, |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1308 SDL_AudioFormat src_fmt, SDL_AudioFormat dst_fmt) |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1309 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1310 if (src_fmt != dst_fmt) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1311 const Uint16 src_bitsize = SDL_AUDIO_BITSIZE(src_fmt); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1312 const Uint16 dst_bitsize = SDL_AUDIO_BITSIZE(dst_fmt); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1313 SDL_AudioFilter filter = SDL_HandTunedTypeCVT(src_fmt, dst_fmt); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1314 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1315 /* No hand-tuned converter? Try the autogenerated ones. */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1316 if (filter == NULL) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1317 int i; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1318 for (i = 0; sdl_audio_type_filters[i].filter != NULL; i++) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1319 const SDL_AudioTypeFilters *filt = &sdl_audio_type_filters[i]; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1320 if ((filt->src_fmt == src_fmt) && (filt->dst_fmt == dst_fmt)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1321 filter = filt->filter; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1322 break; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1323 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1324 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1325 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1326 if (filter == NULL) { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1327 return -1; /* Still no matching converter?! */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1328 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1329 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1330 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1331 /* Update (cvt) with filter details... */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1332 cvt->filters[cvt->filter_index++] = filter; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1333 if (src_bitsize < dst_bitsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1334 const int mult = (dst_bitsize / src_bitsize); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1335 cvt->len_mult *= mult; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1336 cvt->len_ratio *= mult; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1337 } else if (src_bitsize > dst_bitsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1338 cvt->len_ratio /= (src_bitsize / dst_bitsize); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1339 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1340 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1341 return 1; /* added a converter. */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1342 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1343 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1344 return 0; /* no conversion necessary. */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1345 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1346 |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1347 /* Generate the necessary IIR lowpass coefficients for resampling. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1348 Assume that the SDL_AudioCVT struct is already set up with |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1349 the correct values for len_mult and len_div, and use the |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1350 type of dst_format. Also assume the buffer is allocated. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1351 Note the buffer needs to be 6 units long. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1352 For now, use RBJ's cookbook coefficients. It might be more |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1353 optimal to create a Butterworth filter, but this is more difficult. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1354 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1355 int |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1356 SDL_BuildIIRLowpass(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1357 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1358 float fc; /* cutoff frequency */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1359 float coeff[6]; /* floating point iir coefficients b0, b1, b2, a0, a1, a2 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1360 float scale; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1361 float w0, alpha, cosw0; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1362 int i; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1363 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1364 /* The higher Q is, the higher CUTOFF can be. Need to find a good balance to avoid aliasing */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1365 static const float Q = 5.0f; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1366 static const float CUTOFF = 0.4f; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1367 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1368 fc = (cvt->len_mult > |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1369 cvt->len_div) ? CUTOFF / (float) cvt->len_mult : CUTOFF / |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1370 (float) cvt->len_div; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1371 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1372 w0 = 2.0f * M_PI * fc; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1373 cosw0 = cosf(w0); |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1374 alpha = sinf(w0) / (2.0f * Q); |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1375 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1376 /* Compute coefficients, normalizing by a0 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1377 scale = 1.0f / (1.0f + alpha); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1378 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1379 coeff[0] = (1.0f - cosw0) / 2.0f * scale; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1380 coeff[1] = (1.0f - cosw0) * scale; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1381 coeff[2] = coeff[0]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1382 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1383 coeff[3] = 1.0f; /* a0 is normalized to 1 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1384 coeff[4] = -2.0f * cosw0 * scale; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1385 coeff[5] = (1.0f - alpha) * scale; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1386 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1387 /* Copy the coefficients to the struct. If necessary, convert coefficients to fixed point, using the range (-2.0, 2.0) */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1388 #define convert_fixed(type, fix) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1389 type *cvt_coeff = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1390 for(i = 0; i < 6; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1391 cvt_coeff[i] = fix(coeff[i]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1392 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1393 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1394 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1395 if (SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1396 float *cvt_coeff = (float *) cvt->coeff; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1397 for (i = 0; i < 6; ++i) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1398 cvt_coeff[i] = coeff[i]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1399 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1400 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1401 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1402 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1403 convert_fixed(Uint8, SDL_Make_2_6); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1404 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1405 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1406 convert_fixed(Uint16, SDL_Make_2_14); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1407 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1408 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1409 convert_fixed(Uint32, SDL_Make_2_30); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1410 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1411 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1412 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1413 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1414 #ifdef DEBUG_CONVERT |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1415 #define debug_iir(type) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1416 type *cvt_coeff = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1417 for(i = 0; i < 6; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1418 printf("coeff[%u] = %f = 0x%x\n", i, coeff[i], cvt_coeff[i]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1419 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1420 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1421 if (SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1422 float *cvt_coeff = (float *) cvt->coeff; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1423 for (i = 0; i < 6; ++i) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1424 printf("coeff[%u] = %f = %f\n", i, coeff[i], cvt_coeff[i]); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1425 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1426 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1427 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1428 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1429 debug_iir(Uint8); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1430 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1431 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1432 debug_iir(Uint16); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1433 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1434 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1435 debug_iir(Uint32); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1436 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1437 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1438 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1439 #undef debug_iir |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1440 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1441 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1442 /* Initialize the state buffer to all zeroes, and set initial position */ |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1443 SDL_memset(cvt->state_buf, 0, 4 * SDL_AUDIO_BITSIZE(format) / 4); |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1444 cvt->state_pos = 0; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1445 #undef convert_fixed |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1446 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1447 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1448 /* Apply the lowpass IIR filter to the given SDL_AudioCVT struct */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1449 /* This was implemented because it would be much faster than the fir filter, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1450 but it doesn't seem to have a steep enough cutoff so we'd need several |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1451 cascaded biquads, which probably isn't a great idea. Therefore, this |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1452 function can probably be discarded. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1453 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1454 static void |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1455 SDL_FilterIIR(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1456 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1457 Uint32 i, n; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1458 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1459 /* TODO: Check that n is calculated right */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1460 n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1461 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1462 /* Note that the coefficients are 2_x and the input is 1_x. Do we need to shift left at the end here? The right shift temp = buf[n] >> 1 needs to depend on whether the type is signed or not for sign extension. */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1463 /* cvt->state_pos = 1: state[0] = x_n-1, state[1] = x_n-2, state[2] = y_n-1, state[3] - y_n-2 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1464 #define iir_fix(type, mult) {\ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1465 type *coeff = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1466 type *state = (type *)cvt->state_buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1467 type *buf = (type *)cvt->buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1468 type temp; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1469 for(i = 0; i < n; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1470 temp = buf[i] >> 1; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1471 if(cvt->state_pos) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1472 buf[i] = mult(coeff[0], temp) + mult(coeff[1], state[0]) + mult(coeff[2], state[1]) - mult(coeff[4], state[2]) - mult(coeff[5], state[3]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1473 state[1] = temp; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1474 state[3] = buf[i]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1475 cvt->state_pos = 0; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1476 } else { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1477 buf[i] = mult(coeff[0], temp) + mult(coeff[1], state[1]) + mult(coeff[2], state[0]) - mult(coeff[4], state[3]) - mult(coeff[5], state[2]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1478 state[0] = temp; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1479 state[2] = buf[i]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1480 cvt->state_pos = 1; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1481 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1482 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1483 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1484 /* Need to test to see if the previous method or this one is faster */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1485 /*#define iir_fix(type, mult) {\ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1486 type *coeff = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1487 type *state = (type *)cvt->state_buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1488 type *buf = (type *)cvt->buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1489 type temp; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1490 for(i = 0; i < n; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1491 temp = buf[i] >> 1; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1492 buf[i] = mult(coeff[0], temp) + mult(coeff[1], state[0]) + mult(coeff[2], state[1]) - mult(coeff[4], state[2]) - mult(coeff[5], state[3]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1493 state[1] = state[0]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1494 state[0] = temp; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1495 state[3] = state[2]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1496 state[2] = buf[i]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1497 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1498 }*/ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1499 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1500 if (SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1501 float *coeff = (float *) cvt->coeff; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1502 float *state = (float *) cvt->state_buf; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1503 float *buf = (float *) cvt->buf; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1504 float temp; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1505 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1506 for (i = 0; i < n; ++i) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1507 /* y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] - a1 * y[n-1] - a[2] * y[n-2] */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1508 temp = buf[i]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1509 if (cvt->state_pos) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1510 buf[i] = |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1511 coeff[0] * buf[n] + coeff[1] * state[0] + |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1512 coeff[2] * state[1] - coeff[4] * state[2] - |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1513 coeff[5] * state[3]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1514 state[1] = temp; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1515 state[3] = buf[i]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1516 cvt->state_pos = 0; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1517 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1518 buf[i] = |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1519 coeff[0] * buf[n] + coeff[1] * state[1] + |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1520 coeff[2] * state[0] - coeff[4] * state[3] - |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1521 coeff[5] * state[2]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1522 state[0] = temp; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1523 state[2] = buf[i]; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1524 cvt->state_pos = 1; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1525 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1526 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1527 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1528 /* Treat everything as signed! */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1529 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1530 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1531 iir_fix(Sint8, SDL_FixMpy8); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1532 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1533 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1534 iir_fix(Sint16, SDL_FixMpy16); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1535 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1536 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1537 iir_fix(Sint32, SDL_FixMpy32); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1538 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1539 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1540 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1541 #undef iir_fix |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1542 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1543 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1544 /* Apply the windowed sinc FIR filter to the given SDL_AudioCVT struct. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1545 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1546 static void |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1547 SDL_FilterFIR(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1548 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1549 int n = 8 * cvt->len_cvt / SDL_AUDIO_BITSIZE(format); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1550 int m = cvt->len_sinc; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1551 int i, j; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1552 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1553 /* |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1554 Note: We can make a big optimization here by taking advantage |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1555 of the fact that the signal is zero stuffed, so we can do |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1556 significantly fewer multiplications and additions. However, this |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1557 depends on the zero stuffing ratio, so it may not pay off. This would |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1558 basically be a polyphase filter. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1559 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1560 /* One other way to do this fast is to look at the fir filter from a different angle: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1561 After we zero stuff, we have input of all zeroes, except for every len_mult |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1562 sample. If we choose a sinc length equal to len_mult, then the fir filter becomes |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1563 much more simple: we're just taking a windowed sinc, shifting it to start at each |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1564 len_mult sample, and scaling it by the value of that sample. If we do this, then |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1565 we don't even need to worry about the sample histories, and the inner loop here is |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1566 unnecessary. This probably sacrifices some quality but could really speed things up as well. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1567 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1568 /* We only calculate the values of samples which are 0 (mod len_div) because |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1569 those are the only ones used. All the other ones are discarded in the |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1570 third step of resampling. This is a huge speedup. As a warning, though, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1571 if for some reason this is used elsewhere where there are no samples discarded, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1572 the output will not be corrrect if len_div is not 1. To make this filter a |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1573 generic FIR filter, simply remove the if statement "if(i % cvt->len_div == 0)" |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1574 around the inner loop so that every sample is processed. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1575 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1576 /* This is basically just a FIR filter. i.e. for input x_n and m coefficients, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1577 y_n = x_n*sinc_0 + x_(n-1)*sinc_1 + x_(n-2)*sinc_2 + ... + x_(n-m+1)*sinc_(m-1) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1578 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1579 #define filter_sinc(type, mult) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1580 type *sinc = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1581 type *state = (type *)cvt->state_buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1582 type *buf = (type *)cvt->buf; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1583 for(i = 0; i < n; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1584 state[cvt->state_pos] = buf[i]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1585 buf[i] = 0; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1586 if( i % cvt->len_div == 0 ) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1587 for(j = 0; j < m; ++j) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1588 buf[i] += mult(sinc[j], state[(cvt->state_pos + j) % m]); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1589 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1590 }\ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1591 cvt->state_pos = (cvt->state_pos + 1) % m; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1592 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1593 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1594 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1595 if (SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1596 filter_sinc(float, SDL_FloatMpy); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1597 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1598 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1599 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1600 filter_sinc(Sint8, SDL_FixMpy8); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1601 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1602 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1603 filter_sinc(Sint16, SDL_FixMpy16); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1604 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1605 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1606 filter_sinc(Sint32, SDL_FixMpy32); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1607 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1608 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1609 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1610 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1611 #undef filter_sinc |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1612 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1613 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1614 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1615 /* Generate the necessary windowed sinc filter for resampling. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1616 Assume that the SDL_AudioCVT struct is already set up with |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1617 the correct values for len_mult and len_div, and use the |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1618 type of dst_format. Also assume the buffer is allocated. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1619 Note the buffer needs to be m+1 units long. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1620 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1621 int |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1622 SDL_BuildWindowedSinc(SDL_AudioCVT * cvt, SDL_AudioFormat format, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1623 unsigned int m) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1624 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1625 float fScale; /* scale factor for fixed point */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1626 float *fSinc; /* floating point sinc buffer, to be converted to fixed point */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1627 float fc; /* cutoff frequency */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1628 float two_pi_fc, two_pi_over_m, four_pi_over_m, m_over_two; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1629 float norm_sum, norm_fact; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1630 unsigned int i; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1631 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1632 /* Check that the buffer is allocated */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1633 if (cvt->coeff == NULL) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1634 return -1; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1635 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1636 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1637 /* Set the length */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1638 cvt->len_sinc = m + 1; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1639 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1640 /* Allocate the floating point windowed sinc. */ |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1641 fSinc = SDL_stack_alloc(float, (m + 1)); |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1642 if (fSinc == NULL) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1643 return -1; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1644 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1645 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1646 /* Set up the filter parameters */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1647 fc = (cvt->len_mult > |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1648 cvt->len_div) ? 0.5f / (float) cvt->len_mult : 0.5f / |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1649 (float) cvt->len_div; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1650 #ifdef DEBUG_CONVERT |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1651 printf("Lowpass cutoff frequency = %f\n", fc); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1652 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1653 two_pi_fc = 2.0f * M_PI * fc; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1654 two_pi_over_m = 2.0f * M_PI / (float) m; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1655 four_pi_over_m = 2.0f * two_pi_over_m; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1656 m_over_two = (float) m / 2.0f; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1657 norm_sum = 0.0f; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1658 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1659 for (i = 0; i <= m; ++i) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1660 if (i == m / 2) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1661 fSinc[i] = two_pi_fc; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1662 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1663 fSinc[i] = |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1664 sinf(two_pi_fc * ((float) i - m_over_two)) / ((float) i - |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1665 m_over_two); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1666 /* Apply blackman window */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1667 fSinc[i] *= |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1668 0.42f - 0.5f * cosf(two_pi_over_m * (float) i) + |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1669 0.08f * cosf(four_pi_over_m * (float) i); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1670 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1671 norm_sum += fabs(fSinc[i]); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1672 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1673 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1674 norm_fact = 1.0f / norm_sum; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1675 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1676 #define convert_fixed(type, fix) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1677 type *dst = (type *)cvt->coeff; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1678 for( i = 0; i <= m; ++i ) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1679 dst[i] = fix(fSinc[i] * norm_fact); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1680 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1681 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1682 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1683 /* If we're using floating point, we only need to normalize */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1684 if (SDL_AUDIO_ISFLOAT(format) && SDL_AUDIO_BITSIZE(format) == 32) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1685 float *fDest = (float *) cvt->coeff; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1686 for (i = 0; i <= m; ++i) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1687 fDest[i] = fSinc[i] * norm_fact; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1688 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1689 } else { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1690 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1691 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1692 convert_fixed(Uint8, SDL_Make_1_7); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1693 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1694 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1695 convert_fixed(Uint16, SDL_Make_1_15); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1696 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1697 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1698 convert_fixed(Uint32, SDL_Make_1_31); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1699 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1700 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1701 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1702 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1703 /* Initialize the state buffer to all zeroes, and set initial position */ |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1704 SDL_memset(cvt->state_buf, 0, |
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1705 cvt->len_sinc * SDL_AUDIO_BITSIZE(format) / 4); |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1706 cvt->state_pos = 0; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1707 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1708 /* Clean up */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1709 #undef convert_fixed |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1710 SDL_stack_free(fSinc); |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1711 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1712 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1713 /* This is used to reduce the resampling ratio */ |
2728
2768bd7281e0
Fixed Visual Studio compilation problems
Sam Lantinga <slouken@libsdl.org>
parents:
2716
diff
changeset
|
1714 static __inline__ int |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1715 SDL_GCD(int a, int b) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1716 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1717 int temp; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1718 while (b != 0) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1719 temp = a % b; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1720 a = b; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1721 b = temp; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1722 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1723 return a; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1724 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1725 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1726 /* Perform proper resampling. This is pretty slow but it's the best-sounding method. */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1727 static void SDLCALL |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1728 SDL_Resample(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1729 { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1730 int i, j; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1731 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1732 #ifdef DEBUG_CONVERT |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1733 printf("Converting audio rate via proper resampling (mono)\n"); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1734 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1735 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1736 #define zerostuff_mono(type) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1737 const type *src = (const type *) (cvt->buf + cvt->len_cvt); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1738 type *dst = (type *) (cvt->buf + (cvt->len_cvt * cvt->len_mult)); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1739 for (i = cvt->len_cvt / sizeof (type); i; --i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1740 src--; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1741 dst[-1] = src[0]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1742 for( j = -cvt->len_mult; j < -1; ++j ) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1743 dst[j] = 0; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1744 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1745 dst -= cvt->len_mult; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1746 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1747 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1748 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1749 #define discard_mono(type) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1750 const type *src = (const type *) (cvt->buf); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1751 type *dst = (type *) (cvt->buf); \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1752 for (i = 0; i < (cvt->len_cvt / sizeof(type)) / cvt->len_div; ++i) { \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1753 dst[0] = src[0]; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1754 src += cvt->len_div; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1755 ++dst; \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1756 } \ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1757 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1758 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1759 /* Step 1: Zero stuff the conversion buffer. This upsamples by a factor of len_mult, |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1760 creating aliasing at frequencies above the original nyquist frequency. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1761 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1762 #ifdef DEBUG_CONVERT |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1763 printf("Zero-stuffing by a factor of %u\n", cvt->len_mult); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1764 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1765 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1766 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1767 zerostuff_mono(Uint8); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1768 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1769 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1770 zerostuff_mono(Uint16); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1771 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1772 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1773 zerostuff_mono(Uint32); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1774 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1775 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1776 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1777 cvt->len_cvt *= cvt->len_mult; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1778 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1779 /* Step 2: Use a windowed sinc FIR filter (lowpass filter) to remove the alias |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1780 frequencies. This is the slow part. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1781 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1782 SDL_FilterFIR(cvt, format); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1783 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1784 /* Step 3: Now downsample by discarding samples. */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1785 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1786 #ifdef DEBUG_CONVERT |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1787 printf("Discarding samples by a factor of %u\n", cvt->len_div); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1788 #endif |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1789 switch (SDL_AUDIO_BITSIZE(format)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1790 case 8: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1791 discard_mono(Uint8); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1792 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1793 case 16: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1794 discard_mono(Uint16); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1795 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1796 case 32: |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1797 discard_mono(Uint32); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1798 break; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1799 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1800 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1801 #undef zerostuff_mono |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1802 #undef discard_mono |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1803 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1804 cvt->len_cvt /= cvt->len_div; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1805 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1806 if (cvt->filters[++cvt->filter_index]) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1807 cvt->filters[cvt->filter_index] (cvt, format); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1808 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1809 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1810 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1811 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1812 /* Creates a set of audio filters to convert from one format to another. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1813 Returns -1 if the format conversion is not supported, 0 if there's |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1814 no conversion needed, or 1 if the audio filter is set up. |
0 | 1815 */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1816 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1817 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1818 SDL_BuildAudioCVT(SDL_AudioCVT * cvt, |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1819 SDL_AudioFormat src_fmt, Uint8 src_channels, int src_rate, |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1820 SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate) |
0 | 1821 { |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1822 /* there are no unsigned types over 16 bits, so catch this upfront. */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1823 if ((SDL_AUDIO_BITSIZE(src_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(src_fmt))) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1824 return -1; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1825 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1826 if ((SDL_AUDIO_BITSIZE(dst_fmt) > 16) && (!SDL_AUDIO_ISSIGNED(dst_fmt))) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1827 return -1; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1828 } |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1829 #ifdef DEBUG_CONVERT |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1830 printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n", |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1831 src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1832 #endif |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1833 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1834 /* Start off with no conversion necessary */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1835 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1836 cvt->src_format = src_fmt; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1837 cvt->dst_format = dst_fmt; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1838 cvt->needed = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1839 cvt->filter_index = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1840 cvt->filters[0] = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1841 cvt->len_mult = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1842 cvt->len_ratio = 1.0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1843 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1844 /* Convert data types, if necessary. Updates (cvt). */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1845 if (SDL_BuildAudioTypeCVT(cvt, src_fmt, dst_fmt) == -1) |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
1846 return -1; /* shouldn't happen, but just in case... */ |
0 | 1847 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1848 /* Channel conversion */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1849 if (src_channels != dst_channels) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1850 if ((src_channels == 1) && (dst_channels > 1)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1851 cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1852 cvt->len_mult *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1853 src_channels = 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1854 cvt->len_ratio *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1855 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1856 if ((src_channels == 2) && (dst_channels == 6)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1857 cvt->filters[cvt->filter_index++] = SDL_ConvertSurround; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1858 src_channels = 6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1859 cvt->len_mult *= 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1860 cvt->len_ratio *= 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1861 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1862 if ((src_channels == 2) && (dst_channels == 4)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1863 cvt->filters[cvt->filter_index++] = SDL_ConvertSurround_4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1864 src_channels = 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1865 cvt->len_mult *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1866 cvt->len_ratio *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1867 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1868 while ((src_channels * 2) <= dst_channels) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1869 cvt->filters[cvt->filter_index++] = SDL_ConvertStereo; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1870 cvt->len_mult *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1871 src_channels *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1872 cvt->len_ratio *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1873 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1874 if ((src_channels == 6) && (dst_channels <= 2)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1875 cvt->filters[cvt->filter_index++] = SDL_ConvertStrip; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1876 src_channels = 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1877 cvt->len_ratio /= 3; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1878 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1879 if ((src_channels == 6) && (dst_channels == 4)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1880 cvt->filters[cvt->filter_index++] = SDL_ConvertStrip_2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1881 src_channels = 4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1882 cvt->len_ratio /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1883 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1884 /* This assumes that 4 channel audio is in the format: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1885 Left {front/back} + Right {front/back} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1886 so converting to L/R stereo works properly. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1887 */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1888 while (((src_channels % 2) == 0) && |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1889 ((src_channels / 2) >= dst_channels)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1890 cvt->filters[cvt->filter_index++] = SDL_ConvertMono; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1891 src_channels /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1892 cvt->len_ratio /= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1893 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1894 if (src_channels != dst_channels) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1895 /* Uh oh.. */ ; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1896 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1897 } |
0 | 1898 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1899 /* Do rate conversion */ |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1900 if (src_rate != dst_rate) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1901 int rate_gcd; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1902 rate_gcd = SDL_GCD(src_rate, dst_rate); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1903 cvt->len_mult = dst_rate / rate_gcd; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1904 cvt->len_div = src_rate / rate_gcd; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1905 cvt->len_ratio = (double) cvt->len_mult / (double) cvt->len_div; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1906 cvt->filters[cvt->filter_index++] = SDL_Resample; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1907 SDL_BuildWindowedSinc(cvt, dst_fmt, 768); |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1908 } |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1909 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1910 /* |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1911 cvt->rate_incr = 0.0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1912 if ((src_rate / 100) != (dst_rate / 100)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1913 Uint32 hi_rate, lo_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1914 int len_mult; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1915 double len_ratio; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1916 SDL_AudioFilter rate_cvt = NULL; |
0 | 1917 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1918 if (src_rate > dst_rate) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1919 hi_rate = src_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1920 lo_rate = dst_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1921 switch (src_channels) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1922 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1923 rate_cvt = SDL_RateDIV2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1924 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1925 case 2: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1926 rate_cvt = SDL_RateDIV2_c2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1927 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1928 case 4: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1929 rate_cvt = SDL_RateDIV2_c4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1930 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1931 case 6: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1932 rate_cvt = SDL_RateDIV2_c6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1933 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1934 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1935 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1936 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1937 len_mult = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1938 len_ratio = 0.5; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1939 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1940 hi_rate = dst_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1941 lo_rate = src_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1942 switch (src_channels) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1943 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1944 rate_cvt = SDL_RateMUL2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1945 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1946 case 2: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1947 rate_cvt = SDL_RateMUL2_c2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1948 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1949 case 4: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1950 rate_cvt = SDL_RateMUL2_c4; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1951 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1952 case 6: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1953 rate_cvt = SDL_RateMUL2_c6; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1954 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1955 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1956 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1957 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1958 len_mult = 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1959 len_ratio = 2.0; |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1960 }*/ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1961 /* If hi_rate = lo_rate*2^x then conversion is easy */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1962 /* while (((lo_rate * 2) / 100) <= (hi_rate / 100)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1963 cvt->filters[cvt->filter_index++] = rate_cvt; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1964 cvt->len_mult *= len_mult; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1965 lo_rate *= 2; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1966 cvt->len_ratio *= len_ratio; |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1967 } */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1968 /* We may need a slow conversion here to finish up */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1969 /* if ((lo_rate / 100) != (hi_rate / 100)) { |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1970 #if 1 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1971 /* The problem with this is that if the input buffer is |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1972 say 1K, and the conversion rate is say 1.1, then the |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1973 output buffer is 1.1K, which may not be an acceptable |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1974 buffer size for the audio driver (not a power of 2) |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1975 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1976 /* For now, punt and hope the rate distortion isn't great. |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1977 */ |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1978 /*#else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1979 if (src_rate < dst_rate) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1980 cvt->rate_incr = (double) lo_rate / hi_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1981 cvt->len_mult *= 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1982 cvt->len_ratio /= cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1983 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1984 cvt->rate_incr = (double) hi_rate / lo_rate; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1985 cvt->len_ratio *= cvt->rate_incr; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1986 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1987 cvt->filters[cvt->filter_index++] = SDL_RateSLOW; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1988 #endif |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1989 } |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
1990 }*/ |
0 | 1991 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1992 /* Set up the filter information */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1993 if (cvt->filter_index != 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1994 cvt->needed = 1; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1995 cvt->src_format = src_fmt; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
1996 cvt->dst_format = dst_fmt; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1997 cvt->len = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1998 cvt->buf = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
1999 cvt->filters[cvt->filter_index] = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
2000 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
2001 return (cvt->needed); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
2002 } |
0 | 2003 |
2716
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2004 #undef SDL_FixMpy8 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2005 #undef SDL_FixMpy16 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2006 #undef SDL_FixMpy32 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2007 #undef SDL_FloatMpy |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2008 #undef SDL_Make_1_7 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2009 #undef SDL_Make_1_15 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2010 #undef SDL_Make_1_31 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2011 #undef SDL_Make_2_6 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2012 #undef SDL_Make_2_14 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2013 #undef SDL_Make_2_30 |
f8f68f47285a
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2130
diff
changeset
|
2014 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
2015 /* vi: set ts=4 sw=4 expandtab: */ |