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