annotate src/audio/SDL_audiocvt.c @ 2014:7abe37467fa5

Replaced unions with calls to SDL_SwapFloat...
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 01 Sep 2006 19:29:49 +0000
parents 8055185ae4ed
children 3908e1f808e1
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Functions for audio drivers to perform runtime conversion of audio format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #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
27 #include "SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 /* 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
30 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
31 SDL_ConvertMono(SDL_AudioCVT * cvt, SDL_AudioFormat format)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 {
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
33 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
34 Sint32 sample;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #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
37 fprintf(stderr, "Converting to mono\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #endif
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
39 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
40 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
41 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
42 Uint8 *src, *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
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
44 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
45 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
46 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
47 sample = src[0] + 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
48 if (sample > 255) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
49 *dst = 255;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
50 } 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
51 *dst = (Uint8) sample;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
52 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
53 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
54 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
55 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
56 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
57 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58
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
59 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
60 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
61 Sint8 *src, *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
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
63 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
64 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
65 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
66 sample = src[0] + 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
67 if (sample > 127) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
68 *dst = 127;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
69 } else if (sample < -128) {
c121d94672cb SDL 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 *dst = -128;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
71 } 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
72 *dst = (Sint8) sample;
c121d94672cb SDL 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 }
c121d94672cb SDL 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 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
75 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
76 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
77 }
c121d94672cb SDL 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 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79
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
80 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
81 {
c121d94672cb SDL 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 Uint8 *src, *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
84 src = 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
85 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
86 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
87 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
88 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
89 (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
90 if (sample > 65535) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
91 dst[0] = 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
92 dst[1] = 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
93 } 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
94 dst[1] = (sample & 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
95 sample >>= 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
96 dst[0] = (sample & 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
97 }
c121d94672cb SDL 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 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
99 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
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 } 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
102 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
103 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
104 (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
105 if (sample > 65535) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
106 dst[0] = 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
107 dst[1] = 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
108 } 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
109 dst[0] = (sample & 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
110 sample >>= 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
111 dst[1] = (sample & 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
112 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
113 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
114 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
115 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
116 }
c121d94672cb SDL 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 }
c121d94672cb SDL 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 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119
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
120 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
121 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
122 Uint8 *src, *dst;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123
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
124 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
125 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
126 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
127 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
128 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
129 (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
130 if (sample > 32767) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
131 dst[0] = 0x7F;
c121d94672cb SDL 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 dst[1] = 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
133 } else if (sample < -32768) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
134 dst[0] = 0x80;
c121d94672cb SDL 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 dst[1] = 0x00;
c121d94672cb SDL 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 } 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
137 dst[1] = (sample & 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
138 sample >>= 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
139 dst[0] = (sample & 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
140 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
141 src += 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
142 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
143 }
c121d94672cb SDL 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 } 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
145 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
146 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
147 (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
148 if (sample > 32767) {
c121d94672cb SDL 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 dst[1] = 0x7F;
c121d94672cb SDL 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[0] = 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
151 } else if (sample < -32768) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
152 dst[1] = 0x80;
c121d94672cb SDL 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 dst[0] = 0x00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
154 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
155 dst[0] = (sample & 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
156 sample >>= 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
157 dst[1] = (sample & 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
158 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
159 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
160 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
161 }
c121d94672cb SDL 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 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
165
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
166 case AUDIO_S32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
167 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
168 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
169 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
170 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
171 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
172 const Sint64 added =
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
173 (((Sint64) (Sint32) SDL_SwapBE32(src[0])) +
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
174 ((Sint64) (Sint32) SDL_SwapBE32(src[1])));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
175 *(dst++) = SDL_SwapBE32((Uint32) ((Sint32) (added >> 1)));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
176 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
177 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
178 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
179 const Sint64 added =
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
180 (((Sint64) (Sint32) SDL_SwapLE32(src[0])) +
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
181 ((Sint64) (Sint32) SDL_SwapLE32(src[1])));
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
182 *(dst++) = SDL_SwapLE32((Uint32) ((Sint32) (added >> 1)));
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
183 }
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 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
187
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
188 case AUDIO_F32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
189 {
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
190 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
191 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
192 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
193 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
194 float src1, src2;
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
195 src1 = SDL_SwapFloatBE(src[0]);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
196 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);
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
198 src1 = (float) (added * 0.5);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
199 *(dst++) = SDL_SwapFloatBE(src1);
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) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
203 float src1, src2;
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
204 src1 = SDL_SwapFloatLE(src[0]);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
205 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
206 const double added = ((double) src1) + ((double) src2);
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
207 src1 = (float) (added * 0.5);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
208 *(dst++) = SDL_SwapFloatLE(src1);
1982
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 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
212 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
213 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
214
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
215 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
216 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
217 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
218 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
221
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
222 /* 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
223 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
224 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
225 {
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
226 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
227
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
228 #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
229 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
230 #endif
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
231
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
232 #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
233 { \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
234 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
235 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
236 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
237 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
238 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
239 src += 6; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
240 dst += 2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
241 } \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
242 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
243
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
244 /* 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
245 switch (SDL_AUDIO_BITSIZE(format)) {
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
246 case 8:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
247 strip_chans_6_to_2(Uint8);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
248 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
249 case 16:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
250 strip_chans_6_to_2(Uint16);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
251 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
252 case 32:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
253 strip_chans_6_to_2(Uint32);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
254 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
255 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
256
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
257 #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
258
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
259 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
260 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
261 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
262 }
942
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
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
266 /* 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
267 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
268 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
269 {
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
270 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
271
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
272 #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
273 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
274 #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
275
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
276 #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
277 { \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285 src += 6; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
286 dst += 4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
287 } \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
288 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
289
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
290 /* 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
291 switch (SDL_AUDIO_BITSIZE(format)) {
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
292 case 8:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
293 strip_chans_6_to_4(Uint8);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
294 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
295 case 16:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
296 strip_chans_6_to_4(Uint16);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
297 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
298 case 32:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
299 strip_chans_6_to_4(Uint32);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
300 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
301 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
302
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
303 #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
304
1982
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 /= 6;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
306 cvt->len_cvt *= 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
307 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
308 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
309 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
310 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 /* 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
313 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
314 SDL_ConvertStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 {
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
316 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 #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
319 fprintf(stderr, "Converting to stereo\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
321
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
322 #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
323 { \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
324 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
325 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
326 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
327 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
328 dst -= 2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
329 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
330 } \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
331 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
333 /* 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
334 switch (SDL_AUDIO_BITSIZE(format)) {
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
335 case 8:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
336 dup_chans_1_to_2(Uint8);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
337 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
338 case 16:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
339 dup_chans_1_to_2(Uint16);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
340 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
341 case 32:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
342 dup_chans_1_to_2(Uint32);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
343 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
344 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
346 #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
347
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
348 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
349 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
350 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
351 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
354
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
355 /* 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
356 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
357 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
358 {
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
359 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
360
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
361 #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
362 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
363 #endif
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
364
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
365 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
366 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
367 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
368 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
369
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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
386 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
387
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
388 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
389 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
390 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
391
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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
408 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
409
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
410 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
411 {
c121d94672cb SDL 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 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
413 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
414
c121d94672cb SDL 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 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
416 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
417
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430 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
431
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
432 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
433 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
434 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
435 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
436
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
437 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
438 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
439 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
440 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
441 }
c121d94672cb SDL 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 } 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
443 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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455
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
456 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
457 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
458 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
459 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
460
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
461 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
462 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
463 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
464 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
468 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
469
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
470 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
471 {
c121d94672cb SDL 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 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
473 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
474
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
475 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
476 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
477
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
478 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
479 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
480 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
481 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
482 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
483 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
484 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
485 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
486 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
487 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
488 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
489 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
490 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
491
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
492 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
493 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
494 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
495 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
496
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
497 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
498 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
499 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
500 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
501 }
c121d94672cb SDL 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 } 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
503 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
504 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
505 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
506 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
507 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
508 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
509 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
510 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
511 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
512 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
513 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
514 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
515
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
516 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
517 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
518 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
519 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
520
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
521 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
522 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
523 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
524 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
528 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
529
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
530 case AUDIO_S32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
531 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
532 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
533 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
534 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
535
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
536 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
537 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
538 dst -= 6;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
539 src -= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 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
549 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
550 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
551 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
552 dst -= 6;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
553 src -= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
554 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
555 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
556 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
557 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
558 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
559 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
560 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
561 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
562 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
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 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
566 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
567
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
568 case AUDIO_F32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
569 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
570 float lf, rf, ce;
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
571 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
572 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
573
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
574 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
575 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
576 dst -= 6;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
577 src -= 2;
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
578 lf = SDL_SwapFloatBE(src[0]);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
579 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
580 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
581 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
582 dst[1] = src[1];
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
583 dst[2] = SDL_SwapFloatBE(lf - ce);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
584 dst[3] = SDL_SwapFloatBE(rf - ce);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
585 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
586 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
587 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
588 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
589 dst -= 6;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
590 src -= 2;
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
591 lf = SDL_SwapFloatLE(src[0]);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
592 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
593 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
594 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
595 dst[1] = src[1];
2014
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
596 dst[2] = SDL_SwapFloatLE(lf - ce);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
597 dst[3] = SDL_SwapFloatLE(rf - ce);
7abe37467fa5 Replaced unions with calls to SDL_SwapFloat...
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
598 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
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 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
602 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
603
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
604 }
c121d94672cb SDL 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 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
606 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
607 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
608 }
942
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
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
612 /* 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
613 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
614 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
615 {
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
616 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
617
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
618 #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
619 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
620 #endif
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
621
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
622 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
623 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
624 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
625 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
626
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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634 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
635 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
636 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
637 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
638 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
641 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
642
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
643 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
644 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
645 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
646
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
647 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
648 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
649 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
650 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
651 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
652 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
653 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
654 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
655 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
656 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
657 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
658 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
661 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
662
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
663 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
664 {
c121d94672cb SDL 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 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
666 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
667
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
668 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
669 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
670
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
671 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
672 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
673 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
674 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
675 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
676 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
677 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
678 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
679 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
680 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
681 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
682 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
683 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
684
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
685 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
686 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
687 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
688 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
689 }
c121d94672cb SDL 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 } 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
691 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
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700 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
701 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
702 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
703
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
704 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
705 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
706 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
707 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
711 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
712
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
713 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
714 {
c121d94672cb SDL 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 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
716 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
717
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
718 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
719 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
720
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
721 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
722 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
723 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
724 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
725 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
726 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
727 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
728 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
729 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
730 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
731 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
732 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
733 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
734
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
735 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
736 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
737 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
738 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
739 }
c121d94672cb SDL 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 } 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
741 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
742 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
743 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
744 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
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753
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
754 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
755 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
756 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
757 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
761 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
762
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
763 case AUDIO_S32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
764 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
765 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
766 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
767 Sint32 lf, rf, ce;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
768
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
769 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
770 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
771 dst -= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
772 src -= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
773 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
774 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
775 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
776 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
777 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
778 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
779 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
780 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
781 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
782 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
783 dst -= 4;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
784 src -= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
785 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
786 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
787 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
788 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
789 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
790 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
791 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
792 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
793 }
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
794 }
c121d94672cb SDL 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 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
796 }
c121d94672cb SDL 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 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
798 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
799 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
800 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
801 }
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
802
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
803 /* 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
804 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
805 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
806 {
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
807 int i;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
808
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
809 #ifdef DEBUG_CONVERT
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
810 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
811 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
812
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
813 #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
814 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
815 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
816 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
817 src--; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
818 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
819 dst -= 2; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
823 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
824 case 8:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
825 mul2_mono(Uint8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
826 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
827 case 16:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
828 mul2_mono(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
829 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
830 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
831 mul2_mono(Uint32);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
832 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
833 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
834
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
835 #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
836
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
837 cvt->len_cvt *= 2;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
838 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
839 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
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
844 /* 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
845 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
846 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
847 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
848 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
849
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
850 #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
851 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
852 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
853
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
854 #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
855 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
856 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
857 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
858 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
859 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
860 src -= 2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
861 dst[-1] = r; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
862 dst[-2] = l; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
863 dst[-3] = r; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
864 dst[-4] = l; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
865 dst -= 4; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
869 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
870 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
871 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
872 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
873 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
874 mul2_stereo(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
875 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
876 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
877 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
878 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
879 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
880
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
881 #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
882
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
883 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
884 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
885 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
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
889 /* 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
890 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
891 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
892 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
893 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
894
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
895 #ifdef DEBUG_CONVERT
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
896 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
897 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
898
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
899 #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
900 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
901 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
902 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
903 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
904 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
905 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
906 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
907 src -= 4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
908 dst[-1] = c1; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
909 dst[-2] = c2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
910 dst[-3] = c3; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
911 dst[-4] = c4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
912 dst[-5] = c1; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
913 dst[-6] = c2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
914 dst[-7] = c3; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
915 dst[-8] = c4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
916 dst -= 8; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
920 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
921 case 8:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
922 mul2_quad(Uint8);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
923 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
924 case 16:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
925 mul2_quad(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
926 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
927 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
928 mul2_quad(Uint32);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
929 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
930 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
931
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
932 #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
933
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
934 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
935 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
936 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
937 }
942
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
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
941 /* 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
942 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
943 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
944 {
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
945 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
946
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
947 #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
948 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
949 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
950
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
951 #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
952 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
953 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
954 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
955 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
956 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
957 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
958 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
959 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
960 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
961 src -= 6; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
962 dst[-1] = c1; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
963 dst[-2] = c2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
964 dst[-3] = c3; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
965 dst[-4] = c4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
966 dst[-5] = c5; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
967 dst[-6] = c6; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
968 dst[-7] = c1; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
969 dst[-8] = c2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
970 dst[-9] = c3; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
971 dst[-10] = c4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
972 dst[-11] = c5; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
973 dst[-12] = c6; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
974 dst -= 12; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
978 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
979 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
980 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
981 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
982 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
983 mul2_chansix(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
984 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
985 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
986 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
987 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
988 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
989
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
990 #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
991
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
992 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
993 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
994 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
995 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
996 }
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
997
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
998 /* 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
999 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1000 SDL_RateDIV2(SDL_AudioCVT * cvt, SDL_AudioFormat format)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1001 {
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
1002 int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1003
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1004 #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
1005 fprintf(stderr, "Converting audio rate / 2 (mono)\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1006 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1007
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1008 #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
1009 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
1010 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
1011 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
1012 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
1013 src += 2; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1014 dst++; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1018 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
1019 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1020 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
1021 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
1022 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1023 div2_mono(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1024 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1025 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1026 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
1027 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
1028 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1029
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1030 #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
1031
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
1032 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
1033 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
1034 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
1035 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1036 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1037
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1038
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1039 /* 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
1040 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1041 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
1042 {
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
1043 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
1044
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1045 #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
1046 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
1047 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1048
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1049 #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
1050 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
1051 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
1052 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
1053 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
1054 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
1055 src += 4; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1056 dst += 2; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1060 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
1061 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1062 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
1063 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
1064 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1065 div2_stereo(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1066 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1067 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1068 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
1069 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
1070 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1071
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1072 #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
1073
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
1074 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
1075 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
1076 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
1077 }
942
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
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1081 /* 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
1082 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1083 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
1084 {
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
1085 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
1086
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1087 #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
1088 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
1089 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1090
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1091 #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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 src += 8; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1100 dst += 4; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1104 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
1105 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1106 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
1107 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
1108 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1109 div2_quad(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1110 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1111 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1112 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
1113 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
1114 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1115
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1116 #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
1117
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
1118 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
1119 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
1120 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
1121 }
942
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
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1124 /* 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
1125 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1126 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
1127 {
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
1128 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
1129
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1130 #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
1131 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
1132 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1133
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1134 #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
1135 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
1136 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
1137 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
1138 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
1139 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
1140 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
1141 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
1142 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
1143 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
1144 src += 12; \
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1145 dst += 6; \
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1149 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
1150 case 8:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1151 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
1152 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
1153 case 16:
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1154 div2_chansix(Uint16);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1155 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1156 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1157 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
1158 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
1159 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1160
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1161 #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
1162
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
1163 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
1164 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
1165 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
1166 }
942
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1167 }
41a59de7f2ed Here are patches for SDL12 and SDL_mixer for 4 or 6 channel
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
1168
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1169 /* 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
1170 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1171 SDL_RateSLOW(SDL_AudioCVT * cvt, SDL_AudioFormat format)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1172 {
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
1173 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
1174 int i, clen;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1175
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1176 #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
1177 fprintf(stderr, "Converting audio rate * %4.4f\n", 1.0 / cvt->rate_incr);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1178 #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
1179 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
1180 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
1181 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
1182 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
1183 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1184 Uint8 *output;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1185
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
1186 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
1187 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
1188 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
1189 *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
1190 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
1191 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1194 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1195
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
1196 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
1197 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1198 Uint16 *output;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1199
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
1200 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
1201 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
1202 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
1203 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
1204 *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
1205 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
1206 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
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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1209 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1210
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1211 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1212 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1213 /* !!! FIXME: need 32-bit converter here! */
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");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1215 }
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
1216 }
c121d94672cb SDL 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 } else {
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1218 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
1219 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
1220 {
c121d94672cb SDL 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 Uint8 *output;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1222
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
1223 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
1224 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
1225 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
1226 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
1227 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
1228 *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
1229 }
c121d94672cb SDL 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 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1232
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
1233 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
1234 {
c121d94672cb SDL 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 Uint16 *output;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1236
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
1237 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
1238 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
1239 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
1240 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
1241 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
1242 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
1243 *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
1244 }
c121d94672cb SDL 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 break;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1247
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1248 case 32:
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1249 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1250 /* !!! FIXME: need 32-bit converter here! */
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1251 fprintf(stderr, "FIXME: need 32-bit converter here!\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1252 }
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
1253 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1254 }
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 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
1257 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
1258 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
1259 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1260 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1261
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
1262 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
1263 SDL_ConvertAudio(SDL_AudioCVT * cvt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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 /* 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
1266 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
1267 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
1268 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
1269 }
c121d94672cb SDL 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 /* 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
1271 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
1272 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
1273 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
1274 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1275
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
1276 /* 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
1277 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
1278 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
1279 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1280 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1281
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1282
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1283 static SDL_AudioFilter
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1284 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
1285 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1286 /*
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1287 * 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
1288 * 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
1289 */
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1290
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1291 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
1292 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1293
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1294
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1295 /*
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1296 * 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
1297 * 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
1298 * 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
1299 * specific data types.
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1300 */
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1301 static int
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1302 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
1303 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
1304 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1305 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
1306 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
1307 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
1308 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
1309
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1310 /* 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
1311 if (filter == NULL) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1312 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1313 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
1314 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
1315 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
1316 filter = filt->filter;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1317 break;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1318 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1319 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1320
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1321 if (filter == NULL) {
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1322 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
1323 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1324 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1325
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1326 /* 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
1327 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
1328 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
1329 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
1330 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
1331 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
1332 } 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
1333 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
1334 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1335
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1336 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
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 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
1340 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1341
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1342
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1343
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1344 /* 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
1345 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
1346 no conversion needed, or 1 if the audio filter is set up.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1347 */
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
1348
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1349 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
1350 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
1351 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
1352 SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1353 {
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1354 /* 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
1355 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
1356 return -1;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1357 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1358 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
1359 return -1;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1360 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
1361 #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
1362 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
1363 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
1364 #endif
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1365
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
1366 /* 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
1367
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1368 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
1369 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
1370 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
1371 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
1372 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
1373 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
1374 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
1375
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1376 /* 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
1377 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
1378 return -1; /* shouldn't happen, but just in case... */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1379
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
1380 /* 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
1381 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
1382 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
1383 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
1384 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
1385 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
1386 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
1387 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1388 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
1389 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
1390 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
1391 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
1392 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
1393 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1394 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
1395 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
1396 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
1397 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
1398 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
1399 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1400 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
1401 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
1402 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
1403 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
1404 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
1405 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1406 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
1407 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
1408 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
1409 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
1410 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1411 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
1412 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
1413 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
1414 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
1415 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1416 /* 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
1417 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
1418 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
1419 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1420 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
1421 ((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
1422 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
1423 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
1424 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
1425 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1426 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
1427 /* 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
1428 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1429 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1430
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
1431 /* Do rate 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
1432 cvt->rate_incr = 0.0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1433 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
1434 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
1435 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
1436 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
1437 SDL_AudioFilter rate_cvt = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1438
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
1439 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
1440 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
1441 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
1442 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
1443 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
1444 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
1445 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
1446 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
1447 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
1448 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
1449 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
1450 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
1451 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
1452 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
1453 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
1454 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
1455 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
1456 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
1457 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1458 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
1459 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
1460 } 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
1461 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
1462 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
1463 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
1464 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
1465 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
1466 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
1467 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
1468 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
1469 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
1470 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
1471 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
1472 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
1473 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
1474 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
1475 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
1476 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
1477 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
1478 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1479 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
1480 len_ratio = 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
1481 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1482 /* If hi_rate = lo_rate*2^x then conversion is easy */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1483 while (((lo_rate * 2) / 100) <= (hi_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
1484 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
1485 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
1486 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
1487 cvt->len_ratio *= len_ratio;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1488 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1489 /* We may need a slow conversion here to finish up */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1490 if ((lo_rate / 100) != (hi_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
1491 #if 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
1492 /* 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
1493 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
1494 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
1495 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
1496 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1497 /* 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
1498 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1499 #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
1500 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
1501 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
1502 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
1503 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
1504 } 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
1505 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
1506 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
1507 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1508 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
1509 #endif
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1510 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1511 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1512
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
1513 /* 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
1514 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
1515 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
1516 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
1517 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
1518 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
1519 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
1520 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
1521 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
1522 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
1523 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1524
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
1525 /* vi: set ts=4 sw=4 expandtab: */