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