Mercurial > SDL_sound_CoreAudio
annotate SDL_sound.c @ 453:b9856ba6fb4e
Updated comments on supported files to include Speex.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 13 Sep 2003 20:35:24 +0000 |
parents | 6d328f00c20d |
children | 3e705c9180e5 50bb9a6cebfe |
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 * | |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
172
diff
changeset
|
26 * Please see the file COPYING in the source's root directory. |
4 | 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 <ctype.h> | |
39 | |
40 #include "SDL.h" | |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
432
diff
changeset
|
41 #include "SDL_thread.h" |
4 | 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 | |
262 | 50 #if (defined SOUND_SUPPORTS_SMPEG) |
51 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SMPEG; | |
52 #endif | |
53 | |
54 #if (defined SOUND_SUPPORTS_MPGLIB) | |
55 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MPGLIB; | |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
56 #endif |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
57 |
209
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
58 #if (defined SOUND_SUPPORTS_MIKMOD) |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
59 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIKMOD; |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
60 #endif |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
61 |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
62 #if (defined SOUND_SUPPORTS_MODPLUG) |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
63 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG; |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
64 #endif |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
65 |
20 | 66 #if (defined SOUND_SUPPORTS_WAV) |
67 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV; | |
68 #endif | |
69 | |
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
|
70 #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
|
71 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
|
72 #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
|
73 |
216
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
74 #if (defined SOUND_SUPPORTS_AU) |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
75 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AU; |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
76 #endif |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
77 |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
78 #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
|
79 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
|
80 #endif |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
81 |
4 | 82 #if (defined SOUND_SUPPORTS_VOC) |
83 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC; | |
84 #endif | |
85 | |
86 #if (defined SOUND_SUPPORTS_RAW) | |
87 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW; | |
88 #endif | |
89 | |
102 | 90 #if (defined SOUND_SUPPORTS_SHN) |
91 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN; | |
92 #endif | |
93 | |
110 | 94 #if (defined SOUND_SUPPORTS_MIDI) |
95 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI; | |
96 #endif | |
97 | |
157 | 98 #if (defined SOUND_SUPPORTS_FLAC) |
99 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC; | |
100 #endif | |
101 | |
322 | 102 #if (defined SOUND_SUPPORTS_QUICKTIME) |
103 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_QuickTime; | |
104 #endif | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
105 |
450 | 106 #if (defined SOUND_SUPPORTS_SPEEX) |
107 extern const Sound_DecoderFunctions __Sound_DecoderFunctions_SPEEX; | |
108 #endif | |
109 | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
110 typedef struct |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
111 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
112 int available; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
113 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
|
114 } decoder_element; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
115 |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
116 static decoder_element decoders[] = |
4 | 117 { |
262 | 118 #if (defined SOUND_SUPPORTS_SMPEG) |
119 { 0, &__Sound_DecoderFunctions_SMPEG }, | |
120 #endif | |
121 | |
122 #if (defined SOUND_SUPPORTS_MPGLIB) | |
123 { 0, &__Sound_DecoderFunctions_MPGLIB }, | |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
124 #endif |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
125 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
126 #if (defined SOUND_SUPPORTS_MODPLUG) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
127 { 0, &__Sound_DecoderFunctions_MODPLUG }, |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
128 #endif |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
129 |
209
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
130 #if (defined SOUND_SUPPORTS_MIKMOD) |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
131 { 0, &__Sound_DecoderFunctions_MIKMOD }, |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
132 #endif |
e63b9393f6ce
Added ModPlug support.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
133 |
20 | 134 #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
|
135 { 0, &__Sound_DecoderFunctions_WAV }, |
20 | 136 #endif |
137 | |
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
|
138 #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
|
139 { 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
|
140 #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
|
141 |
216
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
142 #if (defined SOUND_SUPPORTS_AU) |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
143 { 0, &__Sound_DecoderFunctions_AU }, |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
144 #endif |
07d0939d40e7
Support for .AU files added.
Ryan C. Gordon <icculus@icculus.org>
parents:
209
diff
changeset
|
145 |
26
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
146 #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
|
147 { 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
|
148 #endif |
ddc3614c9042
Bugfix (thanks Tsuyoshi Iguchi!), and Ogg Vorbis decoder entry.
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
149 |
4 | 150 #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
|
151 { 0, &__Sound_DecoderFunctions_VOC }, |
4 | 152 #endif |
153 | |
154 #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
|
155 { 0, &__Sound_DecoderFunctions_RAW }, |
4 | 156 #endif |
102 | 157 |
158 #if (defined SOUND_SUPPORTS_SHN) | |
159 { 0, &__Sound_DecoderFunctions_SHN }, | |
160 #endif | |
110 | 161 |
163
b6d6f994e970
Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents:
157
diff
changeset
|
162 #if (defined SOUND_SUPPORTS_FLAC) |
b6d6f994e970
Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents:
157
diff
changeset
|
163 { 0, &__Sound_DecoderFunctions_FLAC }, |
b6d6f994e970
Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents:
157
diff
changeset
|
164 #endif |
b6d6f994e970
Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents:
157
diff
changeset
|
165 |
110 | 166 #if (defined SOUND_SUPPORTS_MIDI) |
167 { 0, &__Sound_DecoderFunctions_MIDI }, | |
168 #endif | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
169 |
322 | 170 #if (defined SOUND_SUPPORTS_QUICKTIME) |
171 { 0, &__Sound_DecoderFunctions_QuickTime }, | |
172 #endif | |
173 | |
450 | 174 #if (defined SOUND_SUPPORTS_SPEEX) |
175 { 0, &__Sound_DecoderFunctions_SPEEX }, | |
176 #endif | |
177 | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
178 { 0, NULL } |
4 | 179 }; |
180 | |
181 | |
182 | |
183 /* General SDL_sound state ... */ | |
184 | |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
185 typedef struct __SOUND_ERRMSGTYPE__ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
186 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
187 Uint32 tid; |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
188 int error_available; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
189 char error_string[128]; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
190 struct __SOUND_ERRMSGTYPE__ *next; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
191 } ErrMsg; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
192 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
193 static ErrMsg *error_msgs = NULL; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
194 static SDL_mutex *errorlist_mutex = NULL; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
195 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
196 static Sound_Sample *sample_list = NULL; /* this is a linked list. */ |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
197 static SDL_mutex *samplelist_mutex = NULL; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
198 |
4 | 199 static const Sound_DecoderInfo **available_decoders = NULL; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
200 static int initialized = 0; |
4 | 201 |
202 | |
203 /* functions ... */ | |
204 | |
205 void Sound_GetLinkedVersion(Sound_Version *ver) | |
206 { | |
207 if (ver != NULL) | |
208 { | |
209 ver->major = SOUND_VER_MAJOR; | |
210 ver->minor = SOUND_VER_MINOR; | |
211 ver->patch = SOUND_VER_PATCH; | |
212 } /* if */ | |
213 } /* Sound_GetLinkedVersion */ | |
214 | |
215 | |
216 int Sound_Init(void) | |
217 { | |
218 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
|
219 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
|
220 size_t total = sizeof (decoders) / sizeof (decoders[0]); |
4 | 221 BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
222 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
223 sample_list = NULL; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
224 error_msgs = NULL; |
4 | 225 |
226 available_decoders = (const Sound_DecoderInfo **) | |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
227 malloc((total) * sizeof (Sound_DecoderInfo *)); |
4 | 228 BAIL_IF_MACRO(available_decoders == NULL, ERR_OUT_OF_MEMORY, 0); |
229 | |
432
ddce7101673e
Call SDL_InitSubSystem instead of SDL_Init, to prevent unwanted initialization
Ryan C. Gordon <icculus@icculus.org>
parents:
400
diff
changeset
|
230 SDL_InitSubSystem(SDL_INIT_AUDIO); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
231 |
226
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
232 errorlist_mutex = SDL_CreateMutex(); |
445
d0393837bfac
Never actually created samplelist_mutex (doh!) ... Thanks, Glenn Maynard!
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
233 samplelist_mutex = SDL_CreateMutex(); |
226
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
234 |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
235 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
|
236 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
237 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
|
238 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
|
239 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
240 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
|
241 pos++; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
242 } /* if */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
243 } /* for */ |
4 | 244 |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
245 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
|
246 |
4 | 247 initialized = 1; |
248 return(1); | |
249 } /* Sound_Init */ | |
250 | |
251 | |
252 int Sound_Quit(void) | |
253 { | |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
254 ErrMsg *err; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
255 ErrMsg *nexterr = NULL; |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
256 size_t i; |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
257 |
4 | 258 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
259 | |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
260 while (((volatile Sound_Sample *) sample_list) != NULL) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
261 Sound_FreeSample(sample_list); |
4 | 262 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
263 initialized = 0; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
264 |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
265 SDL_DestroyMutex(samplelist_mutex); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
266 samplelist_mutex = NULL; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
267 sample_list = NULL; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
268 |
118
fd942c1433f8
Fixed for win32 compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
110
diff
changeset
|
269 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
|
270 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
271 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
|
272 { |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
273 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
|
274 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
|
275 } /* if */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
276 } /* for */ |
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
277 |
4 | 278 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
|
279 free((void *) available_decoders); |
4 | 280 available_decoders = NULL; |
281 | |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
282 /* clean up error state for each thread... */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
283 SDL_LockMutex(errorlist_mutex); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
284 for (err = error_msgs; err != NULL; err = nexterr) |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
285 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
286 nexterr = err->next; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
287 free(err); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
288 } /* for */ |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
289 error_msgs = NULL; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
290 SDL_UnlockMutex(errorlist_mutex); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
291 SDL_DestroyMutex(errorlist_mutex); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
292 errorlist_mutex = NULL; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
293 |
4 | 294 return(1); |
295 } /* Sound_Quit */ | |
296 | |
297 | |
298 const Sound_DecoderInfo **Sound_AvailableDecoders(void) | |
299 { | |
300 return(available_decoders); /* READ. ONLY. */ | |
301 } /* Sound_AvailableDecoders */ | |
302 | |
303 | |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
304 static ErrMsg *findErrorForCurrentThread(void) |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
305 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
306 ErrMsg *i; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
307 Uint32 tid; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
308 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
309 if (error_msgs != NULL) |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
310 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
311 tid = SDL_ThreadID(); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
312 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
313 SDL_LockMutex(errorlist_mutex); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
314 for (i = error_msgs; i != NULL; i = i->next) |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
315 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
316 if (i->tid == tid) |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
317 { |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
318 SDL_UnlockMutex(errorlist_mutex); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
319 return(i); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
320 } /* if */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
321 } /* for */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
322 SDL_UnlockMutex(errorlist_mutex); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
323 } /* if */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
324 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
325 return(NULL); /* no error available. */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
326 } /* findErrorForCurrentThread */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
327 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
328 |
4 | 329 const char *Sound_GetError(void) |
330 { | |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
331 const char *retval = NULL; |
226
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
332 ErrMsg *err; |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
333 |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
334 if (!initialized) |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
335 return(ERR_NOT_INITIALIZED); |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
336 |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
337 err = findErrorForCurrentThread(); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
338 if ((err != NULL) && (err->error_available)) |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
339 { |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
340 retval = err->error_string; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
341 err->error_available = 0; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
342 } /* if */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
343 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
344 return(retval); |
4 | 345 } /* Sound_GetError */ |
346 | |
347 | |
348 void Sound_ClearError(void) | |
349 { | |
226
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
350 ErrMsg *err; |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
351 |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
352 if (!initialized) |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
353 return; |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
354 |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
355 err = findErrorForCurrentThread(); |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
356 if (err != NULL) |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
357 err->error_available = 0; |
4 | 358 } /* Sound_ClearError */ |
359 | |
360 | |
361 /* | |
362 * This is declared in the internal header. | |
363 */ | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
364 void __Sound_SetError(const char *str) |
4 | 365 { |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
366 ErrMsg *err; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
367 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
368 if (str == NULL) |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
369 return; |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
370 |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
371 SNDDBG(("__Sound_SetError(\"%s\");%s\n", str, |
226
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
372 (initialized) ? "" : " [NOT INITIALIZED!]")); |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
373 |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
374 if (!initialized) |
57e16a6d244f
Fixed an incorrect assertion.
Ryan C. Gordon <icculus@icculus.org>
parents:
223
diff
changeset
|
375 return; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
376 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
377 err = findErrorForCurrentThread(); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
378 if (err == NULL) |
165
9b26ed9eaf04
Whoops; I should read the code before I change it next time; regressing
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
379 { |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
380 err = (ErrMsg *) malloc(sizeof (ErrMsg)); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
381 if (err == NULL) |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
382 return; /* uhh...? */ |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
383 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
384 memset((void *) err, '\0', sizeof (ErrMsg)); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
385 err->tid = SDL_ThreadID(); |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
386 |
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
387 SDL_LockMutex(errorlist_mutex); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
388 err->next = error_msgs; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
389 error_msgs = err; |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
390 SDL_UnlockMutex(errorlist_mutex); |
165
9b26ed9eaf04
Whoops; I should read the code before I change it next time; regressing
Ryan C. Gordon <icculus@icculus.org>
parents:
163
diff
changeset
|
391 } /* if */ |
219
ca3483f4cfec
Error message management now keeps state per-thread, and does not use
Ryan C. Gordon <icculus@icculus.org>
parents:
216
diff
changeset
|
392 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
393 err->error_available = 1; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
394 strncpy(err->error_string, str, sizeof (err->error_string)); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
395 err->error_string[sizeof (err->error_string) - 1] = '\0'; |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
396 } /* __Sound_SetError */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
397 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
398 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
399 Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
400 { |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
401 /* "frames" == "sample frames" */ |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
432
diff
changeset
|
402 float frames_per_ms = ((float) info->rate) / 1000.0f; |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
403 Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms)); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
404 Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels; |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
405 return(frame_offset * frame_size); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
406 } /* __Sound_convertMsToBytePos */ |
4 | 407 |
408 | |
409 /* | |
410 * -ansi and -pedantic flags prevent use of strcasecmp() on Linux, and | |
411 * I honestly don't want to mess around with figuring out if a given | |
412 * platform has "strcasecmp", "stricmp", or | |
413 * "compare_two_damned_strings_case_insensitive", which I hear is in the | |
414 * next release of Carbon. :) This is exported so decoders may use it if | |
415 * they like. | |
416 */ | |
417 int __Sound_strcasecmp(const char *x, const char *y) | |
418 { | |
419 int ux, uy; | |
420 | |
98
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
421 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
|
422 return(0); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
423 |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
424 if (x == NULL) |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
425 return(-1); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
426 |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
427 if (y == NULL) |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
428 return(1); |
dfdf7b4e05bd
Changed __Sound_strcasecmp() to handle NULL strings gracefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
80
diff
changeset
|
429 |
4 | 430 do |
431 { | |
432 ux = toupper((int) *x); | |
433 uy = toupper((int) *y); | |
434 if (ux > uy) | |
435 return(1); | |
436 else if (ux < uy) | |
437 return(-1); | |
438 x++; | |
439 y++; | |
440 } while ((ux) && (uy)); | |
441 | |
442 return(0); | |
443 } /* __Sound_strcasecmp */ | |
444 | |
445 | |
446 /* | |
447 * Allocate a Sound_Sample, and fill in most of its fields. Those that need | |
448 * to be filled in later, by a decoder, will be initialized to zero. | |
449 */ | |
450 static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired, | |
451 Uint32 bufferSize) | |
452 { | |
453 Sound_Sample *retval = malloc(sizeof (Sound_Sample)); | |
454 Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal)); | |
455 if ((retval == NULL) || (internal == NULL)) | |
456 { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
457 __Sound_SetError(ERR_OUT_OF_MEMORY); |
4 | 458 if (retval) |
459 free(retval); | |
460 if (internal) | |
461 free(internal); | |
462 | |
463 return(NULL); | |
464 } /* if */ | |
465 | |
466 memset(retval, '\0', sizeof (Sound_Sample)); | |
467 memset(internal, '\0', sizeof (Sound_SampleInternal)); | |
468 | |
469 assert(bufferSize > 0); | |
470 retval->buffer = malloc(bufferSize); /* pure ugly. */ | |
471 if (!retval->buffer) | |
472 { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
473 __Sound_SetError(ERR_OUT_OF_MEMORY); |
4 | 474 free(internal); |
475 free(retval); | |
476 return(NULL); | |
477 } /* if */ | |
478 memset(retval->buffer, '\0', bufferSize); | |
479 retval->buffer_size = bufferSize; | |
480 | |
481 if (desired != NULL) | |
482 memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo)); | |
483 | |
484 internal->rw = rw; | |
485 retval->opaque = internal; | |
486 return(retval); | |
487 } /* alloc_sample */ | |
488 | |
489 | |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
490 #if (defined DEBUG_CHATTER) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
491 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
|
492 { |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
493 switch(fmt) |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
494 { |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
495 case AUDIO_U8: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
496 return("U8"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
497 case AUDIO_S8: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
498 return("S8"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
499 case AUDIO_U16LSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
500 return("U16LSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
501 case AUDIO_S16LSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
502 return("S16LSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
503 case AUDIO_U16MSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
504 return("U16MSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
505 case AUDIO_S16MSB: |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
506 return("S16MSB"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
507 } /* switch */ |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
508 |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
509 return("Unknown"); |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
510 } /* fmt_to_str */ |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
511 #endif |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
512 |
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
513 |
4 | 514 /* |
515 * The bulk of the Sound_NewSample() work is done here... | |
516 * Ask the specified decoder to handle the data in (rw), and if | |
517 * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream | |
518 * back to where it was, and return false. | |
519 */ | |
520 static int init_sample(const Sound_DecoderFunctions *funcs, | |
521 Sound_Sample *sample, const char *ext, | |
522 Sound_AudioInfo *_desired) | |
523 { | |
524 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
|
525 Sound_AudioInfo desired; |
400 | 526 int pos = SDL_RWtell(internal->rw); |
4 | 527 |
528 /* fill in the funcs for this decoder... */ | |
529 sample->decoder = &funcs->info; | |
530 internal->funcs = funcs; | |
531 if (!funcs->open(sample, ext)) | |
532 { | |
533 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
534 return(0); | |
535 } /* if */ | |
536 | |
537 /* success; we've got a decoder! */ | |
538 | |
539 /* Now we need to set up the conversion buffer... */ | |
540 | |
541 memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual, | |
542 sizeof (Sound_AudioInfo)); | |
543 | |
340
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
544 if (desired.format == 0) |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
545 desired.format = sample->actual.format; |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
546 if (desired.channels == 0) |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
547 desired.channels = sample->actual.channels; |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
548 if (desired.rate == 0) |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
549 desired.rate = sample->actual.rate; |
5a72981b8cba
Added optional, experimental audio conversion routines by Frank Ranostaj.
Ryan C. Gordon <icculus@icculus.org>
parents:
322
diff
changeset
|
550 |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
551 if (Sound_BuildAudioCVT(&internal->sdlcvt, |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
552 sample->actual.format, |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
553 sample->actual.channels, |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
554 sample->actual.rate, |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
555 desired.format, |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
556 desired.channels, |
382
ce998ee6194f
Sync'd with latest altcvt.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
557 desired.rate, |
ce998ee6194f
Sync'd with latest altcvt.
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
558 sample->buffer_size) == -1) |
4 | 559 { |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
560 __Sound_SetError(SDL_GetError()); |
4 | 561 funcs->close(sample); |
562 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
563 return(0); | |
564 } /* if */ | |
565 | |
566 if (internal->sdlcvt.len_mult > 1) | |
567 { | |
568 void *rc = realloc(sample->buffer, | |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
569 sample->buffer_size * internal->sdlcvt.len_mult); |
4 | 570 if (rc == NULL) |
571 { | |
572 funcs->close(sample); | |
573 SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */ | |
574 return(0); | |
575 } /* if */ | |
576 | |
577 sample->buffer = rc; | |
578 } /* if */ | |
579 | |
580 /* these pointers are all one and the same. */ | |
581 memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo)); | |
582 internal->sdlcvt.buf = internal->buffer = sample->buffer; | |
583 internal->buffer_size = sample->buffer_size / internal->sdlcvt.len_mult; | |
584 internal->sdlcvt.len = internal->buffer_size; | |
585 | |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
586 /* Prepend our new Sound_Sample to the sample_list... */ |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
587 SDL_LockMutex(samplelist_mutex); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
588 internal->next = sample_list; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
589 if (sample_list != NULL) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
590 ((Sound_SampleInternal *) sample_list->opaque)->prev = sample; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
591 sample_list = sample; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
592 SDL_UnlockMutex(samplelist_mutex); |
4 | 593 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
594 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
|
595 fmt_to_str(sample->desired.format), |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
596 sample->desired.rate, |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
597 sample->desired.channels)); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
598 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
599 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
|
600 fmt_to_str(sample->actual.format), |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
601 sample->actual.rate, |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
602 sample->actual.channels)); |
10
cc2c32349380
Some debugging output, and MP3 and VOC entries, added.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
603 |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
604 SNDDBG(("On-the-fly conversion: %s.\n", |
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
48
diff
changeset
|
605 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
|
606 |
4 | 607 return(1); |
608 } /* init_sample */ | |
609 | |
610 | |
611 Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, | |
612 Sound_AudioInfo *desired, Uint32 bSize) | |
613 { | |
614 Sound_Sample *retval; | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
615 decoder_element *decoder; |
4 | 616 |
617 /* sanity checks. */ | |
618 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | |
619 BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL); | |
620 | |
621 retval = alloc_sample(rw, desired, bSize); | |
622 if (!retval) | |
623 return(NULL); /* alloc_sample() sets error message... */ | |
624 | |
625 if (ext != NULL) | |
626 { | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
627 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++) |
4 | 628 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
629 if (decoder->available) |
4 | 630 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
631 const char **decoderExt = decoder->funcs->info.extensions; |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
632 while (*decoderExt) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
633 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
634 if (__Sound_strcasecmp(*decoderExt, ext) == 0) |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
635 { |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
636 if (init_sample(decoder->funcs, retval, ext, desired)) |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
637 return(retval); |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
638 break; /* done with this decoder either way. */ |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
639 } /* if */ |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
640 decoderExt++; |
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
641 } /* while */ |
4 | 642 } /* if */ |
643 } /* for */ | |
644 } /* if */ | |
645 | |
646 /* no direct extension match? Try everything we've got... */ | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
647 for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++) |
4 | 648 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
143
diff
changeset
|
649 if (decoder->available) |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
650 { |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
651 int should_try = 1; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
652 const char **decoderExt = decoder->funcs->info.extensions; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
653 |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
654 /* skip if we would have tried decoder above... */ |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
655 while (*decoderExt) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
656 { |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
657 if (__Sound_strcasecmp(*decoderExt, ext) == 0) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
658 { |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
659 should_try = 0; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
660 break; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
661 } /* if */ |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
662 decoderExt++; |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
663 } /* while */ |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
664 |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
665 if (should_try) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
666 { |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
667 if (init_sample(decoder->funcs, retval, ext, desired)) |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
668 return(retval); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
669 } /* if */ |
48
c4b8c39a9798
Individual decoders are now initialized during Sound_Init(), and deinitialized
Ryan C. Gordon <icculus@icculus.org>
parents:
37
diff
changeset
|
670 } /* if */ |
4 | 671 } /* for */ |
672 | |
673 /* nothing could handle the sound data... */ | |
674 free(retval->opaque); | |
675 if (retval->buffer != NULL) | |
676 free(retval->buffer); | |
677 free(retval); | |
678 SDL_RWclose(rw); | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
679 __Sound_SetError(ERR_UNSUPPORTED_FORMAT); |
4 | 680 return(NULL); |
681 } /* Sound_NewSample */ | |
682 | |
683 | |
684 Sound_Sample *Sound_NewSampleFromFile(const char *filename, | |
685 Sound_AudioInfo *desired, | |
686 Uint32 bufferSize) | |
687 { | |
688 const char *ext; | |
689 SDL_RWops *rw; | |
690 | |
691 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); | |
692 BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL); | |
693 | |
694 ext = strrchr(filename, '.'); | |
695 rw = SDL_RWFromFile(filename, "rb"); | |
696 BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL); | |
697 | |
698 if (ext != NULL) | |
699 ext++; | |
700 | |
701 return(Sound_NewSample(rw, ext, desired, bufferSize)); | |
702 } /* Sound_NewSampleFromFile */ | |
703 | |
704 | |
705 void Sound_FreeSample(Sound_Sample *sample) | |
706 { | |
707 Sound_SampleInternal *internal; | |
708 | |
709 if (!initialized) | |
710 { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
711 __Sound_SetError(ERR_NOT_INITIALIZED); |
4 | 712 return; |
713 } /* if */ | |
714 | |
715 if (sample == NULL) | |
716 { | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
717 __Sound_SetError(ERR_INVALID_ARGUMENT); |
4 | 718 return; |
719 } /* if */ | |
720 | |
721 internal = (Sound_SampleInternal *) sample->opaque; | |
722 | |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
723 SDL_LockMutex(samplelist_mutex); |
4 | 724 |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
725 /* update the sample_list... */ |
4 | 726 if (internal->prev != NULL) |
727 { | |
728 Sound_SampleInternal *prevInternal; | |
729 prevInternal = (Sound_SampleInternal *) internal->prev->opaque; | |
730 prevInternal->next = internal->next; | |
731 } /* if */ | |
732 else | |
733 { | |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
734 assert(sample_list == sample); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
735 sample_list = internal->next; |
4 | 736 } /* else */ |
737 | |
738 if (internal->next != NULL) | |
739 { | |
740 Sound_SampleInternal *nextInternal; | |
741 nextInternal = (Sound_SampleInternal *) internal->next->opaque; | |
742 nextInternal->prev = internal->prev; | |
743 } /* if */ | |
744 | |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
745 SDL_UnlockMutex(samplelist_mutex); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
746 |
4 | 747 /* nuke it... */ |
237
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
748 internal->funcs->close(sample); |
ceadd952319a
Increased ModPlug decoder's priority to be above MikMod. Fixed some coding
Ryan C. Gordon <icculus@icculus.org>
parents:
226
diff
changeset
|
749 |
4 | 750 if (internal->rw != NULL) /* this condition is a "just in case" thing. */ |
751 SDL_RWclose(internal->rw); | |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
752 |
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
753 if ((internal->buffer != NULL) && (internal->buffer != sample->buffer)) |
4 | 754 free(internal->buffer); |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
755 |
4 | 756 free(internal); |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
757 |
4 | 758 if (sample->buffer != NULL) |
759 free(sample->buffer); | |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
760 |
4 | 761 free(sample); |
762 } /* Sound_FreeSample */ | |
763 | |
764 | |
765 int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize) | |
766 { | |
767 void *newBuf = NULL; | |
768 Sound_SampleInternal *internal = NULL; | |
769 | |
770 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
771 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0); | |
772 internal = ((Sound_SampleInternal *) sample->opaque); | |
773 newBuf = realloc(sample->buffer, newSize * internal->sdlcvt.len_mult); | |
774 BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0); | |
775 | |
776 internal->sdlcvt.buf = internal->buffer = sample->buffer = newBuf; | |
777 sample->buffer_size = newSize; | |
778 internal->buffer_size = newSize / internal->sdlcvt.len_mult; | |
779 internal->sdlcvt.len = internal->buffer_size; | |
780 | |
781 return(1); | |
782 } /* Sound_SetBufferSize */ | |
783 | |
784 | |
785 Uint32 Sound_Decode(Sound_Sample *sample) | |
786 { | |
787 Sound_SampleInternal *internal = NULL; | |
788 Uint32 retval = 0; | |
789 | |
790 /* a boatload of sanity checks... */ | |
791 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
792 BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0); | |
793 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0); | |
794 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0); | |
795 | |
796 internal = (Sound_SampleInternal *) sample->opaque; | |
797 | |
798 assert(sample->buffer != NULL); | |
799 assert(sample->buffer_size > 0); | |
800 assert(internal->buffer != NULL); | |
801 assert(internal->buffer_size > 0); | |
802 | |
803 /* reset EAGAIN. Decoder can flip it back on if it needs to. */ | |
311
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
804 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN; |
4 | 805 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
|
806 |
163
b6d6f994e970
Moved MIDI decoder to end of array. Fixed Sound_SetError() so that it
Ryan C. Gordon <icculus@icculus.org>
parents:
157
diff
changeset
|
807 if (retval > 0 && internal->sdlcvt.needed) |
4 | 808 { |
809 internal->sdlcvt.len = retval; | |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
810 Sound_ConvertAudio(&internal->sdlcvt); |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
118
diff
changeset
|
811 retval = internal->sdlcvt.len_cvt; |
4 | 812 } /* if */ |
813 | |
814 return(retval); | |
815 } /* Sound_Decode */ | |
816 | |
817 | |
818 Uint32 Sound_DecodeAll(Sound_Sample *sample) | |
819 { | |
820 Sound_SampleInternal *internal = NULL; | |
821 void *buf = NULL; | |
822 Uint32 newBufSize = 0; | |
823 | |
824 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); | |
172
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
825 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_EOF, ERR_PREV_EOF, 0); |
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
826 BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_PREV_ERROR, 0); |
4 | 827 |
828 internal = (Sound_SampleInternal *) sample->opaque; | |
829 | |
830 while ( ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) && | |
831 ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) ) | |
832 { | |
172
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
833 Uint32 br = Sound_Decode(sample); |
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
834 void *ptr = realloc(buf, newBufSize + br); |
4 | 835 if (ptr == NULL) |
836 { | |
837 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
382
diff
changeset
|
838 __Sound_SetError(ERR_OUT_OF_MEMORY); |
4 | 839 } /* if */ |
840 else | |
841 { | |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
842 buf = ptr; |
4 | 843 memcpy( ((char *) buf) + newBufSize, sample->buffer, br ); |
844 newBufSize += br; | |
845 } /* else */ | |
846 } /* while */ | |
847 | |
172
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
848 if (buf == NULL) /* ...in case first call to realloc() fails... */ |
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
849 return(sample->buffer_size); |
705dcbf94639
Sound_DecodeAll() is now more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
167
diff
changeset
|
850 |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
851 if (internal->buffer != sample->buffer) |
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
852 free(internal->buffer); |
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
853 |
4 | 854 free(sample->buffer); |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
855 |
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
856 internal->sdlcvt.buf = internal->buffer = sample->buffer = buf; |
4 | 857 sample->buffer_size = newBufSize; |
858 internal->buffer_size = newBufSize / internal->sdlcvt.len_mult; | |
167
82acaa7107c2
Fixed Sound_DecodeAll(), and made Sound_FreeSample() a little more robust.
Ryan C. Gordon <icculus@icculus.org>
parents:
165
diff
changeset
|
859 internal->sdlcvt.len = internal->buffer_size; |
4 | 860 |
861 return(newBufSize); | |
862 } /* Sound_DecodeAll */ | |
863 | |
223
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
864 |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
865 int Sound_Rewind(Sound_Sample *sample) |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
866 { |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
867 Sound_SampleInternal *internal; |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
868 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
869 |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
870 internal = (Sound_SampleInternal *) sample->opaque; |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
871 if (!internal->funcs->rewind(sample)) |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
872 { |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
873 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
874 return(0); |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
875 } /* if */ |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
876 |
311
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
877 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN; |
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
878 sample->flags &= ~SOUND_SAMPLEFLAG_ERROR; |
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
879 sample->flags &= ~SOUND_SAMPLEFLAG_EOF; |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
880 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
881 return(1); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
882 } /* Sound_Rewind */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
883 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
884 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
885 int Sound_Seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
886 { |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
887 Sound_SampleInternal *internal; |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
888 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
889 BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
890 if (!(sample->flags & SOUND_SAMPLEFLAG_CANSEEK)) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
891 BAIL_MACRO(ERR_CANNOT_SEEK, 0); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
892 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
893 internal = (Sound_SampleInternal *) sample->opaque; |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
894 BAIL_IF_MACRO(!internal->funcs->seek(sample, ms), NULL, 0); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
895 |
311
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
896 sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN; |
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
897 sample->flags &= ~SOUND_SAMPLEFLAG_ERROR; |
d62c05322a3e
Logic fixes from Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
898 sample->flags &= ~SOUND_SAMPLEFLAG_EOF; |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
899 |
223
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
900 return(1); |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
901 } /* Sound_Rewind */ |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
902 |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
219
diff
changeset
|
903 |
4 | 904 /* end of SDL_sound.c ... */ |
905 |