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