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