Mercurial > SDL_sound_CoreAudio
annotate SDL_sound.c @ 119:254916e602c6
Updated.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 06 Oct 2001 22:11:09 +0000 |
parents | fd942c1433f8 |
children | 3e60862fbd76 |
rev | line source |
---|---|
4 | 1 /* |
2 * SDL_sound -- An abstract sound format decoding API. | |
3 * Copyright (C) 2001 Ryan C. Gordon. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 /** | |
21 * This file implements the core API, which is relatively simple. | |
22 * The real meat of SDL_sound is in the decoders directory. | |
23 * | |
24 * Documentation is in SDL_sound.h ... It's verbose, honest. :) | |
25 * | |
26 * Please see the file LICENSE in the source's root directory. | |
27 * | |
28 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
29 */ | |
30 | |
107
427541211bfd
config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents:
102
diff
changeset
|
31 #if HAVE_CONFIG_H |
427541211bfd
config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents:
102
diff
changeset
|
32 # include <config.h> |
427541211bfd
config.h management updates.
Ryan C. Gordon <icculus@icculus.org>
parents:
102
diff
changeset
|
33 #endif |
4 | 34 |
35 #include <stdio.h> | |
36 #include <stdlib.h> | |
37 #include <string.h> | |
38 #include <assert.h> | |
39 #include <ctype.h> | |
40 | |
41 #include "SDL.h" | |
42 #include "SDL_sound.h" | |
43 | |
44 #define __SDL_SOUND_INTERNAL__ | |
45 #include "SDL_sound_internal.h" | |
46 | |
47 | |
48 /* The various decoder drivers... */ | |
49 | |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
50 #if (defined SOUND_SUPPORTS_MP3) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
51 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3; |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
52 #endif |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
53 |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
54 #if (defined SOUND_SUPPORTS_MOD) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
55 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MOD; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
56 #endif |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
57 |
20 | 58 #if (defined SOUND_SUPPORTS_WAV) |
59 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV; | |
60 #endif | |
61 | |
37
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
62 #if (defined SOUND_SUPPORTS_AIFF) |
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
63 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF; |
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
64 #endif |
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
65 |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
66 #if (defined SOUND_SUPPORTS_OGG) |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
67 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG; |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
68 #endif |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
69 |
4 | 70 #if (defined SOUND_SUPPORTS_VOC) |
71 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC; | |
72 #endif | |
73 | |
74 #if (defined SOUND_SUPPORTS_RAW) | |
75 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW; | |
76 #endif | |
77 | |
102 | 78 #if (defined SOUND_SUPPORTS_SHN) |
79 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN; | |
80 #endif | |
81 | |
110 | 82 #if (defined SOUND_SUPPORTS_MIDI) |
83 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI; | |
84 #endif | |
85 | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
86 |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
87 |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
88 typedef struct |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
89 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
90 int available; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
91 const Sound_DecoderFunctions *funcs; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
92 } decoder_element; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
93 |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
94 static decoder_element decoders[] = |
4 | 95 { |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
96 #if (defined SOUND_SUPPORTS_MP3) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
97 { 0, &__Sound_DecoderFunctions_MP3 }, |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
98 #endif |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
99 |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
100 #if (defined SOUND_SUPPORTS_MOD) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
101 { 0, &__Sound_DecoderFunctions_MOD }, |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
102 #endif |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
103 |
20 | 104 #if (defined SOUND_SUPPORTS_WAV) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
105 { 0, &__Sound_DecoderFunctions_WAV }, |
20 | 106 #endif |
107 | |
37
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
108 #if (defined SOUND_SUPPORTS_AIFF) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
109 { 0, &__Sound_DecoderFunctions_AIFF }, |
37
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
110 #endif |
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
111 |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
112 #if (defined SOUND_SUPPORTS_OGG) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
113 { 0, &__Sound_DecoderFunctions_OGG }, |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
114 #endif |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
115 |
4 | 116 #if (defined SOUND_SUPPORTS_VOC) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
117 { 0, &__Sound_DecoderFunctions_VOC }, |
4 | 118 #endif |
119 | |
120 #if (defined SOUND_SUPPORTS_RAW) | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
121 { 0, &__Sound_DecoderFunctions_RAW }, |
4 | 122 #endif |
102 | 123 |
124 #if (defined SOUND_SUPPORTS_SHN) | |
125 { 0, &__Sound_DecoderFunctions_SHN }, | |
126 #endif | |
110 | 127 |
128 #if (defined SOUND_SUPPORTS_MIDI) | |
129 { 0, &__Sound_DecoderFunctions_MIDI }, | |
130 #endif | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
131 |
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
132 { 0, NULL } |
4 | 133 }; |
134 | |
135 | |
136 | |
137 /* General SDL_sound state ... */ | |
138 | |
139 static int initialized = 0; | |
140 static Sound_Sample *samplesList = NULL; /* this is a linked list. */ | |
141 static const Sound_DecoderInfo **available_decoders = NULL; | |
142 | |
143 | |
144 /* functions ... */ | |
145 | |
146 void Sound_GetLinkedVersion(Sound_Version *ver) | |
147 { | |
148 if (ver != NULL) | |
149 { | |
150 ver->major = SOUND_VER_MAJOR; | |
151 ver->minor = SOUND_VER_MINOR; | |
152 ver->patch = SOUND_VER_PATCH; | |
153 } /* if */ | |
154 } /* Sound_GetLinkedVersion */ | |
155 | |
156 | |
157 int Sound_Init(void) | |
158 { | |
159 size_t i; | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
160 size_t pos = 0; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
161 size_t total = sizeof (decoders) / sizeof (decoders[0]); |
4 | 162 BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); |
163 samplesList = NULL; | |
164 | |
165 SDL_Init(SDL_INIT_AUDIO); | |
166 | |
167 available_decoders = (const Sound_DecoderInfo **) | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
168 malloc((total) * sizeof (Sound_DecoderInfo *)); |
4 | 169 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0); |
170 | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
171 for (i = 0; decoders[i].funcs != NULL; i++) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
172 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
173 decoders[i].available = decoders[i].funcs->init(); |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
174 if (decoders[i].available) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
175 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
176 available_decoders[pos] = &(decoders[i].funcs->info); |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
177 pos++; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
178 } /* if */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
179 } /* for */ |
4 | 180 |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
181 available_decoders[pos] = NULL; |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
182 |
4 | 183 initialized = 1; |
184 return(1); | |
185 } /* Sound_Init */ | |
186 | |
187 | |
188 int Sound_Quit(void) | |
189 { | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
190 size_t i; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
191 |
4 | 192 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
193 | |
194 while (((volatile Sound_Sample *) samplesList) != NULL) | |
195 Sound_FreeSample(samplesList); | |
196 | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
197 for (i = 0; decoders[i].funcs != NULL; i++) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
198 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
199 if (decoders[i].available) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
200 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
201 decoders[i].funcs->quit(); |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
202 decoders[i].available = 0; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
203 } /* if */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
204 } /* for */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
205 |
4 | 206 if (available_decoders != NULL) |
80
25ee62c6b333
Fixed a const complaint from Visual C++ 6.0.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
207 free((void *) available_decoders); |
4 | 208 available_decoders = NULL; |
209 | |
210 initialized = 0; | |
211 | |
212 return(1); | |
213 } /* Sound_Quit */ | |
214 | |
215 | |
216 const Sound_DecoderInfo **Sound_AvailableDecoders(void) | |
217 { | |
218 return(available_decoders); /* READ. ONLY. */ | |
219 } /* Sound_AvailableDecoders */ | |
220 | |
221 | |
222 const char *Sound_GetError(void) | |
223 { | |
224 return(SDL_GetError()); | |
225 } /* Sound_GetError */ | |
226 | |
227 | |
228 void Sound_ClearError(void) | |
229 { | |
230 SDL_ClearError(); | |
231 } /* Sound_ClearError */ | |
232 | |
233 | |
234 /* | |
235 * This is declared in the internal header. | |
236 */ | |
237 void Sound_SetError(const char *err) | |
238 { | |
239 if (err != NULL) | |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
240 { |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
241 SNDDBG(("Sound_SetError(\"%s\");\n", err)); |
4 | 242 SDL_SetError(err); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
243 } /* if */ |
4 | 244 } /* Sound_SetError */ |
245 | |
246 | |
247 /* | |
248 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and | |
249 * I honestly don't want to mess around with figuring out if a given | |
250 * platform has "strcasecmp", "stricmp", or | |
251 * "compare_two_damned_strings_case_insensitive", which I hear is in the | |
252 * next release of Carbon. :) This is exported so decoders may use it if | |
253 * they like. | |
254 */ | |
255 int __Sound_strcasecmp(const char *x, const char *y) | |
256 { | |
257 int ux, uy; | |
258 | |
98
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
259 if (x == y) /* same pointer? Both NULL? */ |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
260 return(0); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
261 |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
262 if (x == NULL) |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
263 return(-1); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
264 |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
265 if (y == NULL) |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
266 return(1); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
267 |
4 | 268 do |
269 { | |
270 ux = toupper((int) *x); | |
271 uy = toupper((int) *y); | |
272 if (ux > uy) | |
273 return(1); | |
274 else if (ux < uy) | |
275 return(-1); | |
276 x++; | |
277 y++; | |
278 } while ((ux) && (uy)); | |
279 | |
280 return(0); | |
281 } /* __Sound_strcasecmp */ | |
282 | |
283 | |
284 /* | |
285 * Allocate a Sound_Sample, and fill in most of its fields. Those that need | |
286 * to be filled in later, by a decoder, will be initialized to zero. | |
287 */ | |
288 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, | |
289 Uint32 bufferSize) | |
290 { | |
291 Sound_Sample *retval = malloc(sizeof (Sound_Sample)); | |
292 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal)); | |
293 if ((retval == NULL) || (internal == NULL)) | |
294 { | |
295 Sound_SetError(ERR_OUT_OF_MEMORY); | |
296 if (retval) | |
297 free(retval); | |
298 if (internal) | |
299 free(internal); | |
300 | |
301 return(NULL); | |
302 } /* if */ | |
303 | |
304 memset(retval, '\0', sizeof (Sound_Sample)); | |
305 memset(internal, '\0', sizeof (Sound_SampleInternal)); | |
306 | |
307 assert(bufferSize > 0); | |
308 retval->buffer = malloc(bufferSize); /* pure ugly. */ | |
309 if (!retval->buffer) | |
310 { | |
311 Sound_SetError(ERR_OUT_OF_MEMORY); | |
312 free(internal); | |
313 free(retval); | |
314 return(NULL); | |
315 } /* if */ | |
316 memset(retval->buffer, '\0', bufferSize); | |
317 retval->buffer_size = bufferSize; | |
318 | |
319 if (desired != NULL) | |
320 memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo)); | |
321 | |
322 internal->rw = rw; | |
323 retval->opaque = internal; | |
324 return(retval); | |
325 } /* alloc_sample */ | |
326 | |
327 | |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
328 #if (defined DEBUG_CHATTER) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
329 static __inline__ const char *fmt_to_str(Uint16 fmt) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
330 { |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
331 switch(fmt) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
332 { |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
333 case AUDIO_U8: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
334 return("U8"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
335 case AUDIO_S8: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
336 return("S8"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
337 case AUDIO_U16LSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
338 return("U16LSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
339 case AUDIO_S16LSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
340 return("S16LSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
341 case AUDIO_U16MSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
342 return("U16MSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
343 case AUDIO_S16MSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
344 return("S16MSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
345 } /* switch */ |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
346 |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
347 return("Unknown"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
348 } /* fmt_to_str */ |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
349 #endif |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
350 |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
351 |
4 | 352 /* |
353 * The bulk of the Sound_NewSample() work is done here... | |
354 * Ask the specified decoder to handle the data in (rw), and if | |
355 * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream | |
356 * back to where it was, and return false. | |
357 * | |
358 * !!! FIXME: This is big, ugly, nasty, and smelly. | |
359 */ | |
360 static int init_sample(const Sound_DecoderFunctions *funcs, | |
361 Sound_Sample *sample, const char *ext, | |
362 Sound_AudioInfo *_desired) | |
363 { | |
364 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
37
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
365 Sound_AudioInfo desired; |
4 | 366 int pos = SDL_RWtell(internal->rw); /* !!! FIXME: Int? Really? */ |
367 | |
368 /* fill in the funcs for this decoder... */ | |
369 sample->decoder = &funcs->info; | |
370 internal->funcs = funcs; | |
371 if (!funcs->open(sample, ext)) | |
372 { | |
373 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
374 return(0); | |
375 } /* if */ | |
376 | |
377 /* success; we've got a decoder! */ | |
378 | |
379 /* Now we need to set up the conversion buffer... */ | |
380 | |
381 memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual, | |
382 sizeof (Sound_AudioInfo)); | |
383 | |
384 if (SDL_BuildAudioCVT(&internal->sdlcvt, | |
385 sample->actual.format, | |
386 sample->actual.channels, | |
387 (int) sample->actual.rate, /* !!! FIXME: Int? Really? */ | |
388 desired.format, | |
389 desired.channels, | |
390 (int) desired.rate) == -1) /* !!! FIXME: Int? Really? */ | |
391 { | |
392 Sound_SetError(SDL_GetError()); | |
393 funcs->close(sample); | |
394 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
395 return(0); | |
396 } /* if */ | |
397 | |
398 if (internal->sdlcvt.len_mult > 1) | |
399 { | |
400 void *rc = realloc(sample->buffer, | |
401 sample->buffer_size * internal->sdlcvt.len_mult); | |
402 if (rc == NULL) | |
403 { | |
404 funcs->close(sample); | |
405 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
406 return(0); | |
407 } /* if */ | |
408 | |
409 sample->buffer = rc; | |
410 } /* if */ | |
411 | |
412 /* these pointers are all one and the same. */ | |
413 memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo)); | |
414 internal->sdlcvt.buf = internal->buffer = sample->buffer; | |
415 internal->buffer_size = sample->buffer_size / internal->sdlcvt.len_mult; | |
416 internal->sdlcvt.len = internal->buffer_size; | |
417 | |
418 /* Prepend our new Sound_Sample to the samplesList... */ | |
419 if (samplesList != NULL) | |
420 { | |
421 internal->next = samplesList; | |
422 if (samplesList != NULL) | |
423 internal->prev = sample; | |
424 } /* if */ | |
425 samplesList = sample; | |
426 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
427 SNDDBG(("New sample DESIRED format: %s format, %d rate, %d channels.\n", |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
428 fmt_to_str(sample->desired.format), |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
429 sample->desired.rate, |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
430 sample->desired.channels)); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
431 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
432 SNDDBG(("New sample ACTUAL format: %s format, %d rate, %d channels.\n", |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
433 fmt_to_str(sample->actual.format), |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
434 sample->actual.rate, |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
435 sample->actual.channels)); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
436 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
437 SNDDBG(("On-the-fly conversion: %s.\n", |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
438 internal->sdlcvt.needed ? "ENABLED" : "DISABLED")); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
439 |
4 | 440 return(1); |
441 } /* init_sample */ | |
442 | |
443 | |
444 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, | |
445 Sound_AudioInfo *desired, Uint32 bSize) | |
446 { | |
447 size_t i; | |
448 Sound_Sample *retval; | |
449 | |
450 /* sanity checks. */ | |
451 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | |
452 BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL); | |
453 | |
454 retval = alloc_sample(rw, desired, bSize); | |
455 if (!retval) | |
456 return(NULL); /* alloc_sample() sets error message... */ | |
457 | |
458 if (ext != NULL) | |
459 { | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
460 for (i = 0; decoders[i].funcs != NULL; i++) |
4 | 461 { |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
462 if (decoders[i].available) |
4 | 463 { |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
464 const char *decoderExt = decoders[i].funcs->info.extension; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
465 if (__Sound_strcasecmp(decoderExt, ext) == 0) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
466 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
467 if (init_sample(decoders[i].funcs, retval, ext, desired)) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
468 return(retval); |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
469 } /* if */ |
4 | 470 } /* if */ |
471 } /* for */ | |
472 } /* if */ | |
473 | |
474 /* no direct extension match? Try everything we've got... */ | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
475 for (i = 0; decoders[i].funcs != NULL; i++) |
4 | 476 { |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
477 if (decoders[i].available) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
478 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
479 if (init_sample(decoders[i].funcs, retval, ext, desired)) |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
480 return(retval); |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
481 } /* if */ |
4 | 482 } /* for */ |
483 | |
484 /* nothing could handle the sound data... */ | |
485 free(retval->opaque); | |
486 if (retval->buffer != NULL) | |
487 free(retval->buffer); | |
488 free(retval); | |
489 SDL_RWclose(rw); | |
490 Sound_SetError(ERR_UNSUPPORTED_FORMAT); | |
491 return(NULL); | |
492 } /* Sound_NewSample */ | |
493 | |
494 | |
495 Sound_Sample *Sound_NewSampleFromFile(const char *filename, | |
496 Sound_AudioInfo *desired, | |
497 Uint32 bufferSize) | |
498 { | |
499 const char *ext; | |
500 SDL_RWops *rw; | |
501 | |
502 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | |
503 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL); | |
504 | |
505 ext = strrchr(filename, '.'); | |
506 rw = SDL_RWFromFile(filename, "rb"); | |
507 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); | |
508 | |
509 if (ext != NULL) | |
510 ext++; | |
511 | |
512 return(Sound_NewSample(rw, ext, desired, bufferSize)); | |
513 } /* Sound_NewSampleFromFile */ | |
514 | |
515 | |
516 void Sound_FreeSample(Sound_Sample *sample) | |
517 { | |
518 Sound_SampleInternal *internal; | |
519 | |
520 if (!initialized) | |
521 { | |
522 Sound_SetError(ERR_NOT_INITIALIZED); | |
523 return; | |
524 } /* if */ | |
525 | |
526 if (sample == NULL) | |
527 { | |
528 Sound_SetError(ERR_INVALID_ARGUMENT); | |
529 return; | |
530 } /* if */ | |
531 | |
532 internal = (Sound_SampleInternal *) sample->opaque; | |
533 | |
534 internal->funcs->close(sample); | |
535 | |
536 /* update the samplesList... */ | |
537 if (internal->prev != NULL) | |
538 { | |
539 Sound_SampleInternal *prevInternal; | |
540 prevInternal = (Sound_SampleInternal *) internal->prev->opaque; | |
541 prevInternal->next = internal->next; | |
542 } /* if */ | |
543 else | |
544 { | |
545 assert(samplesList == sample); | |
546 samplesList = internal->next; | |
547 } /* else */ | |
548 | |
549 if (internal->next != NULL) | |
550 { | |
551 Sound_SampleInternal *nextInternal; | |
552 nextInternal = (Sound_SampleInternal *) internal->next->opaque; | |
553 nextInternal->prev = internal->prev; | |
554 } /* if */ | |
555 | |
556 /* nuke it... */ | |
557 if (internal->rw != NULL) /* this condition is a "just in case" thing. */ | |
558 SDL_RWclose(internal->rw); | |
559 assert(internal->buffer != NULL); | |
560 if (internal->buffer != sample->buffer) | |
561 free(internal->buffer); | |
562 free(internal); | |
563 if (sample->buffer != NULL) | |
564 free(sample->buffer); | |
565 free(sample); | |
566 } /* Sound_FreeSample */ | |
567 | |
568 | |
569 int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize) | |
570 { | |
571 void *newBuf = NULL; | |
572 Sound_SampleInternal *internal = NULL; | |
573 | |
574 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
575 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0); | |
576 internal = ((Sound_SampleInternal *) sample->opaque); | |
577 newBuf = realloc(sample->buffer, newSize * internal->sdlcvt.len_mult); | |
578 BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0); | |
579 | |
580 internal->sdlcvt.buf = internal->buffer = sample->buffer = newBuf; | |
581 sample->buffer_size = newSize; | |
582 internal->buffer_size = newSize / internal->sdlcvt.len_mult; | |
583 internal->sdlcvt.len = internal->buffer_size; | |
584 | |
585 return(1); | |
586 } /* Sound_SetBufferSize */ | |
587 | |
588 | |
589 Uint32 Sound_Decode(Sound_Sample *sample) | |
590 { | |
591 Sound_SampleInternal *internal = NULL; | |
592 Uint32 retval = 0; | |
593 | |
594 /* a boatload of sanity checks... */ | |
595 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
596 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0); | |
597 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0); | |
598 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0); | |
599 | |
600 internal = (Sound_SampleInternal *) sample->opaque; | |
601 | |
602 assert(sample->buffer != NULL); | |
603 assert(sample->buffer_size > 0); | |
604 assert(internal->buffer != NULL); | |
605 assert(internal->buffer_size > 0); | |
606 | |
607 /* reset EAGAIN. Decoder can flip it back on if it needs to. */ | |
608 sample->flags &= !SOUND_SAMPLEFLAG_EAGAIN; | |
609 retval = internal->funcs->read(sample); | |
37
f27bcbcaeab1
Added AIFF entry, and (for now) some multiple-streams-in-one-rwops support.
Ryan C. Gordon <icculus@icculus.org>
parents:
26
diff
changeset
|
610 |
4 | 611 if (internal->sdlcvt.needed) |
612 { | |
613 internal->sdlcvt.len = retval; | |
614 SDL_ConvertAudio(&internal->sdlcvt); | |
615 retval *= internal->sdlcvt.len_mult; | |
616 } /* if */ | |
617 | |
618 return(retval); | |
619 } /* Sound_Decode */ | |
620 | |
621 | |
622 Uint32 Sound_DecodeAll(Sound_Sample *sample) | |
623 { | |
624 Sound_SampleInternal *internal = NULL; | |
625 void *buf = NULL; | |
626 Uint32 newBufSize = 0; | |
627 | |
628 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
629 | |
630 internal = (Sound_SampleInternal *) sample->opaque; | |
631 | |
632 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) && | |
633 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) ) | |
634 { | |
635 void *ptr = realloc(buf, newBufSize + sample->buffer_size); | |
636 if (ptr == NULL) | |
637 { | |
638 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
639 Sound_SetError(ERR_OUT_OF_MEMORY); | |
640 } /* if */ | |
641 else | |
642 { | |
643 Uint32 br = Sound_Decode(sample); | |
644 memcpy( ((char *) buf) + newBufSize, sample->buffer, br ); | |
645 newBufSize += br; | |
646 } /* else */ | |
647 } /* while */ | |
648 | |
649 free(sample->buffer); | |
650 sample->buffer = internal->buffer = internal->sdlcvt.buf = buf; | |
651 sample->buffer_size = newBufSize; | |
652 internal->buffer_size = newBufSize / internal->sdlcvt.len_mult; | |
653 internal->sdlcvt.len_mult = internal->buffer_size; | |
654 | |
655 return(newBufSize); | |
656 } /* Sound_DecodeAll */ | |
657 | |
658 | |
659 /* end of SDL_sound.c ... */ | |
660 |