Mercurial > SDL_sound_CoreAudio
annotate SDL_sound.h @ 106:40de367eb59e
Changing my include structure to do this right.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 03 Oct 2001 18:29:32 +0000 |
parents | 78470d7d94de |
children | ac49f81e42d6 |
rev | line source |
---|---|
0 | 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 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data | |
22 * into this library, and SDL_sound will take that data, in one of several | |
23 * popular formats, and decode it into raw waveform data in the format of | |
24 * your choice. This gives you a nice abstraction for getting sound into your | |
25 * game or application; just feed it to SDL_sound, and it will handle | |
26 * decoding and converting, so you can just pass it to your SDL audio | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
27 * callback (or whatever). Since it gets data from an SDL_RWops, you can get |
0 | 28 * the initial sound data from any number of sources: file, memory buffer, |
29 * network connection, etc. | |
30 * | |
31 * As the name implies, this library depends on SDL: Simple Directmedia Layer, | |
32 * which is a powerful, free, and cross-platform multimedia library. It can | |
33 * be found at http://www.libsdl.org/ | |
34 * | |
35 * Support is in place or planned for the following sound formats: | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
36 * - .WAV (Microsoft WAVfile RIFF data, internal.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
37 * - .VOC (Creative Labs' Voice format, internal.) |
11 | 38 * - .MP3 (MPEG-1 Layer 3 support, via the SMPEG library.) |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
39 * - .MID (MIDI music converted to Waveform data, via Timidity.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
40 * - .MOD (MOD files, via MikMod.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
41 * - .OGG (Ogg files, via Ogg Vorbis libraries.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
42 * - .RAW (Raw sound data in any format, internal.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
43 * - .CDA (CD audio read into a sound buffer, internal.) |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
44 * - .AU |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
45 * - .AIFF |
0 | 46 * |
47 * (...and more to come...) | |
48 * | |
49 * Please see the file LICENSE in the source's root directory. | |
50 * | |
51 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
52 */ | |
53 | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
54 #ifndef _INCLUDE_SDL_SOUND_H_ |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
55 #define _INCLUDE_SDL_SOUND_H_ |
0 | 56 |
57 #include "SDL.h" | |
19
734e5d75acec
Now includes SDL_endian.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
15
diff
changeset
|
58 #include "SDL_endian.h" |
0 | 59 |
60 #ifdef __cplusplus | |
61 extern "C" { | |
62 #endif | |
63 | |
29 | 64 #define SOUND_VER_MAJOR 0 |
65 #define SOUND_VER_MINOR 1 | |
44
78470d7d94de
Changed version to 0.1.2.
Ryan C. Gordon <icculus@icculus.org>
parents:
29
diff
changeset
|
66 #define SOUND_VER_PATCH 2 |
29 | 67 |
68 | |
0 | 69 /* |
70 * These are flags that are used in a Sound_Sample (below) to show various | |
71 * states. | |
72 * | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
73 * To use: "if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }" |
0 | 74 */ |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
75 typedef enum __SOUND_SAMPLEFLAGS__ |
0 | 76 { |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
77 SOUND_SAMPLEFLAG_NONE = 0, /* Null flag. */ |
0 | 78 |
79 /* these are set at sample creation time... */ | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
80 SOUND_SAMPLEFLAG_NEEDSEEK = 1, /* SDL_RWops must be able to seek. */ |
0 | 81 |
82 /* these are set during decoding... */ | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
83 SOUND_SAMPLEFLAG_EOF = 1 << 29, /* end of input stream. */ |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
84 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /* unrecoverable error. */ |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
85 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /* would block, or temp error. */ |
0 | 86 } Sound_SampleFlags; |
87 | |
88 | |
89 /* | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
90 * Basics of a decoded sample's data structure: data format (see AUDIO_U8 and |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
91 * friends in SDL_audio.h), number of channels, and sample rate. If you need |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
92 * more explanation than that, you should stop developing sound code right |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
93 * now. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
94 */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
95 typedef struct __SOUND_AUDIOINFO__ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
96 { |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
97 Uint16 format; |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
98 Uint8 channels; |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
99 Uint32 rate; |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
100 } Sound_AudioInfo; |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
101 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
102 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
103 /* |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
104 * Each decoder sets up one of these structs, which can be retrieved via |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
105 * the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
106 */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
107 typedef struct __SOUND_DECODERINFO__ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
108 { |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
109 const char *extension; /* standard file extension. "MP3", "WAV"... */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
110 const char *description; /* Human readable description of decoder. */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
111 const char *author; /* "Name Of Author <email@emailhost.dom>" */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
112 const char *url; /* URL specific to this decoder. */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
113 } Sound_DecoderInfo; |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
114 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
115 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
116 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
117 /* |
0 | 118 * The Sound_Sample structure is the heart of SDL_sound. This holds |
119 * information about a source of sound data as it is being decoded. | |
120 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to | |
121 * change them. | |
122 */ | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
123 typedef struct __SOUND_SAMPLE__ |
0 | 124 { |
125 void *opaque; /* Internal use only. */ | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
126 const Sound_DecoderInfo *decoder; /* Decoder used for this sample. */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
127 Sound_AudioInfo desired; /* Desired audio format for conversion. */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
128 Sound_AudioInfo actual; /* Actual audio format of sample. */ |
0 | 129 void *buffer; /* Decoded sound data lands in here. */ |
130 Uint32 buffer_size; /* Current size of (buffer), in bytes. */ | |
131 Sound_SampleFlags flags; /* Flags relating to this sample. */ | |
132 } Sound_Sample; | |
133 | |
134 | |
135 /* | |
136 * Just what it says: a x.y.z style version number... | |
137 */ | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
138 typedef struct __SOUND_VERSION__ |
0 | 139 { |
140 int major; | |
141 int minor; | |
142 int patch; | |
143 } Sound_Version; | |
144 | |
145 | |
146 | |
147 /* functions and macros... */ | |
148 | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
149 #define SOUND_VERSION(x) { \ |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
150 (x)->major = SOUND_VER_MAJOR; \ |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
151 (x)->minor = SOUND_VER_MINOR; \ |
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
152 (x)->patch = SOUND_VER_PATCH; \ |
0 | 153 } |
154 | |
155 /** | |
156 * Get the version of SDL_sound that is linked against your program. If you | |
157 * are using a shared library (DLL) version of SDL_sound, then it is possible | |
158 * that it will be different than the version you compiled against. | |
159 * | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
160 * This is a real function; the macro SOUND_VERSION tells you what version |
0 | 161 * of SDL_sound you compiled against: |
162 * | |
163 * Sound_Version compiled; | |
164 * Sound_Version linked; | |
165 * | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
166 * SOUND_VERSION(&compiled); |
0 | 167 * Sound_GetLinkedVersion(&linked); |
168 * printf("We compiled against SDL_sound version %d.%d.%d ...\n", | |
169 * compiled.major, compiled.minor, compiled.patch); | |
170 * printf("But we linked against SDL_sound version %d.%d.%d.\n", | |
171 * linked.major, linked.minor, linked.patch); | |
172 * | |
173 * This function may be called safely at any time, even before Sound_Init(). | |
174 */ | |
175 extern DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver); | |
176 | |
177 | |
178 /** | |
179 * Initialize SDL_sound. This must be called before any other SDL_sound | |
180 * function (except perhaps Sound_GetLinkedVersion()). You should call | |
181 * SDL_Init() before calling this. Sound_Init() will attempt to call | |
182 * SDL_Init(SDL_INIT_AUDIO), just in case. This is a safe behaviour, but it | |
183 * may not configure SDL to your liking by itself. | |
184 * | |
185 * @return nonzero on success, zero on error. Specifics of the error can be | |
186 * gleaned from Sound_GetLastError(). | |
187 */ | |
188 extern DECLSPEC int Sound_Init(void); | |
189 | |
190 | |
191 /** | |
192 * Shutdown SDL_sound. This closes any SDL_RWops that were being used as | |
193 * sound sources, and frees any resources in use by SDL_sound. | |
194 * | |
195 * All Sound_Sample pointers you had prior to this call are INVALIDATED. | |
196 * | |
197 * Once successfully deinitialized, Sound_Init() can be called again to | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
198 * restart the subsystem. All default API states are restored at this |
0 | 199 * point. |
200 * | |
201 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit() | |
202 * for you! | |
203 * | |
204 * @return nonzero on success, zero on error. Specifics of the error can be | |
205 * gleaned from Sound_GetLastError(). If failure, state of SDL_sound | |
206 * is undefined, and probably badly screwed up. | |
207 */ | |
208 extern DECLSPEC int Sound_Quit(void); | |
209 | |
210 | |
211 /** | |
212 * Get a list of sound formats supported by this implementation of SDL_sound. | |
213 * This is for informational purposes only. Note that the extension listed is | |
11 | 214 * merely convention: if we list "MP3", you can open an MPEG-1 Layer 3 audio |
0 | 215 * file with an extension of "XYZ", if you like. The file extensions are |
216 * informational, and only required as a hint to choosing the correct | |
217 * decoder, since the sound data may not be coming from a file at all, thanks | |
218 * to the abstraction that an SDL_RWops provides. | |
219 * | |
220 * The returned value is an array of pointers to Sound_DecoderInfo structures, | |
221 * with a NULL entry to signify the end of the list: | |
222 * | |
223 * Sound_DecoderInfo **i; | |
224 * | |
225 * for (i = Sound_AvailableDecoders(); *i != NULL; i++) | |
226 * { | |
227 * printf("Supported sound format: [%s], which is [%s].\n", | |
228 * i->extension, i->description); | |
229 * // ...and other fields... | |
230 * } | |
231 * | |
232 * The return values are pointers to static internal memory, and should | |
233 * be considered READ ONLY, and never freed. | |
234 * | |
235 * @return READ ONLY Null-terminated array of READ ONLY structures. | |
236 */ | |
237 extern DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void); | |
238 | |
239 | |
240 /** | |
241 * Get the last SDL_sound error message as a null-terminated string. | |
242 * This will be NULL if there's been no error since the last call to this | |
243 * function. The pointer returned by this call points to an internal buffer. | |
244 * Each thread has a unique error state associated with it, but each time | |
245 * a new error message is set, it will overwrite the previous one associated | |
246 * with that thread. It is safe to call this function at anytime, even | |
247 * before Sound_Init(). | |
248 * | |
249 * @return READ ONLY string of last error message. | |
250 */ | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
251 extern DECLSPEC const char *Sound_GetError(void); |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
252 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
253 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
254 /** |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
255 * Clear the current error message, so the next call to Sound_GetError() will |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
256 * return NULL. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
257 */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
258 extern DECLSPEC void Sound_ClearError(void); |
0 | 259 |
260 | |
261 /** | |
262 * Start decoding a new sound sample. The data is read via an SDL_RWops | |
263 * structure (see SDL_rwops.h in the SDL include directory), so it may be | |
264 * coming from memory, disk, network stream, etc. The (ext) parameter is | |
265 * merely a hint to determining the correct decoder; if you specify, for | |
266 * example, "mp3" for an extension, and one of the decoders lists that | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
267 * as a handled extension, then that decoder is given first shot at trying |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
268 * to claim the data for decoding. If none of the extensions match (or the |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
269 * extension is NULL), then every decoder examines the data to determine if |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
270 * it can handle it, until one accepts it. In such a case your SDL_RWops will |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
271 * need to be capable of rewinding to the start of the stream. |
0 | 272 * If no decoders can handle the data, a NULL value is returned, and a human |
273 * readable error message can be fetched from Sound_GetLastError(). | |
274 * Optionally, a desired audio format can be specified. If the incoming data | |
275 * is in a different format, SDL_sound will convert it to the desired format | |
276 * on the fly. Note that this can be an expensive operation, so it may be | |
277 * wise to convert data before you need to play it back, if possible, or | |
278 * make sure your data is initially in the format that you need it in. | |
279 * If you don't want to convert the data, you can specify NULL for a desired | |
280 * format. The incoming format of the data, preconversion, can be found | |
281 * in the Sound_Sample structure. | |
282 * Note that the raw sound data "decoder" needs you to specify both the | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
283 * extension "RAW" and a "desired" format, or it will refuse to handle |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
284 * the data. This is to prevent it from catching all formats unsupported |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
285 * by the other decoders. |
0 | 286 * Finally, specify an initial buffer size; this is the number of bytes that |
287 * will be allocated to store each read from the sound buffer. The more you | |
288 * can safely allocate, the more decoding can be done in one block, but the | |
289 * more resources you have to use up, and the longer each decoding call will | |
290 * take. Note that different data formats require more or less space to | |
291 * store. This buffer can be resized via Sound_SetBufferSize() ... | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
292 * The buffer size specified must be a multiple of the size of a single |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
293 * sample (not to be confused with a single Sound_Sample). So, if you want |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
294 * 16-bit, stereo samples, then your sample size is (2 channels * 16 bits), |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
295 * or 32 bits per sample, which is four bytes. In such a case, you could |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
296 * specify 128 or 132 bytes for a buffer, but not 129, 130, or 131, although |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
297 * in reality, you'll want to specify a MUCH larger buffer. |
0 | 298 * When you are done with this Sound_Sample pointer, you can dispose of it |
299 * via Sound_FreeSample(). | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
300 * You do not have to keep a reference to (rw) around. If this function |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
301 * suceeds, it stores (rw) internally (and disposes of it during the call |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
302 * to Sound_FreeSample()). If this function fails, it will dispose of the |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
303 * SDL_RWops for you. |
0 | 304 * |
305 * @param rw SDL_RWops with sound data. | |
306 * @param ext File extension normally associated with a data format. | |
307 * Can usually be NULL. | |
308 * @param desired Format to convert sound data into. Can usually be NULL, | |
309 * if you don't need conversion. | |
310 * @return Sound_Sample pointer, which is used as a handle to several other | |
311 * SDL_sound APIs. NULL on error. If error, use | |
312 * Sound_GetLastError() to see what went wrong. | |
313 */ | |
314 extern DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
315 Sound_AudioInfo *desired, |
0 | 316 Uint32 bufferSize); |
317 | |
318 /** | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
319 * This is identical to Sound_NewSample(), but it creates an SDL_RWops for you |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
320 * from the file located in (filename). Note that (filename) is specified in |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
321 * platform-dependent notation. ("C:\\music\\mysong.mp3" on windows, and |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
322 * "/home/icculus/music/mysong.mp3" or whatever on Unix, etc.) |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
323 * Sound_NewSample()'s "ext" parameter is gleaned from the contents of |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
324 * (filename). |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
325 * |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
326 * @param filename file containing sound data. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
327 * @param desired Format to convert sound data into. Can usually be NULL, |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
328 * if you don't need conversion. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
329 * @param bufferSize size, in bytes, of initial read buffer. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
330 * @return Sound_Sample pointer, which is used as a handle to several other |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
331 * SDL_sound APIs. NULL on error. If error, use |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
332 * Sound_GetLastError() to see what went wrong. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
333 */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
334 extern DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename, |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
335 Sound_AudioInfo *desired, |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
336 Uint32 bufferSize); |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
337 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
338 /** |
0 | 339 * Dispose of a Sound_Sample pointer that was returned from Sound_NewSample(). |
340 * This will also close/dispose of the SDL_RWops that was used at creation | |
341 * time, so there's no need to keep a reference to that around. | |
342 * The Sound_Sample pointer is invalid after this call, and will almost | |
343 * certainly result in a crash if you attempt to keep using it. | |
344 * | |
345 * @param sample The Sound_Sample to delete. | |
346 */ | |
347 extern DECLSPEC void Sound_FreeSample(Sound_Sample *sample); | |
348 | |
349 | |
350 /** | |
3
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
351 * Change the current buffer size for a sample. If the buffer size could |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
352 * be changed, then the sample->buffer and sample->buffer_size fields will |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
353 * reflect that. If they could not be changed, then your original sample |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
354 * state is preserved. If the buffer is shrinking, the data at the end of |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
355 * buffer is truncated. If the buffer is growing, the contents of the new |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
356 * space at the end is undefined until you decode more into it or initialize |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
357 * it yourself. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
358 * |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
359 * The buffer size specified must be a multiple of the size of a single |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
360 * sample (not to be confused with a single Sound_Sample). So, if you want |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
361 * 16-bit, stereo samples, then your sample size is (2 channels * 16 bits), |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
362 * or 32 bits per sample, which is four bytes. In such a case, you could |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
363 * specify 128 or 132 bytes for a buffer, but not 129, 130, or 131, although |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
364 * in reality, you'll want to specify a MUCH larger buffer. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
365 * |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
366 * @param sample The Sound_Sample whose buffer to modify. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
367 * @param new_size The desired size, in bytes, of the new buffer. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
368 * @return non-zero if buffer size changed, zero on failure. |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
369 */ |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
370 extern DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size); |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
371 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
372 |
fd6cd0e04e6f
First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
1
diff
changeset
|
373 /** |
0 | 374 * Decode more of the sound data in a Sound_Sample. It will decode at most |
375 * sample->buffer_size bytes into sample->buffer in the desired format, and | |
376 * return the number of decoded bytes. | |
377 * If sample->buffer_size bytes could not be decoded, then please refer to | |
378 * sample->flags to determine if this was an End-of-stream or error condition. | |
379 * | |
380 * @param sample Do more decoding to this Sound_Sample. | |
381 * @return number of bytes decoded into sample->buffer. If it is less than | |
382 * sample->buffer_size, then you should check sample->flags to see | |
383 * what the current state of the sample is (EOF, error, read again). | |
384 */ | |
385 extern DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample); | |
386 | |
387 | |
388 /** | |
389 * Decode the remainder of the sound data in a Sound_Sample. This will | |
390 * dynamically allocate memory for the ENTIRE remaining sample. | |
391 * sample->buffer_size and sample->buffer will be updated to reflect the | |
392 * new buffer. Please refer to sample->flags to determine if the decoding | |
393 * finished due to an End-of-stream or error condition. | |
394 * | |
395 * Be aware that sound data can take a large amount of memory, and that | |
396 * this function may block for quite awhile while processing. Also note | |
397 * that a streaming source (for example, from a SDL_RWops that is getting | |
398 * fed from an Internet radio feed that doesn't end) may fill all available | |
399 * memory before giving up...be sure to use this on finite sound sources | |
400 * only! | |
401 * | |
402 * @param sample Do all decoding for this Sound_Sample. | |
403 * @return number of bytes decoded into sample->buffer. If it is less than | |
404 * sample->buffer_size, then you should check sample->flags to see | |
405 * what the current state of the sample is (EOF, error, read again). | |
406 */ | |
407 extern DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample); | |
408 | |
409 #ifdef __cplusplus | |
410 } | |
411 #endif | |
412 | |
1
508aac690b19
Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
413 #endif /* !defined _INCLUDE_SDL_SOUND_H_ */ |
0 | 414 |
415 /* end of SDL_sound.h ... */ | |
416 |