Skip to content

Latest commit

 

History

History
737 lines (678 loc) · 27.8 KB

SDL_sound.h

File metadata and controls

737 lines (678 loc) · 27.8 KB
 
Jun 7, 2002
Jun 7, 2002
1
2
/** \file SDL_sound.h */
Sep 14, 2001
Sep 14, 2001
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* SDL_sound -- An abstract sound format decoding API.
* Copyright (C) 2001 Ryan C. Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
Jun 7, 2002
Jun 7, 2002
23
24
25
26
* \mainpage SDL_sound
*
* The latest version of SDL_sound can be found at:
* http://icculus.org/SDL_sound/
Dec 26, 2001
Dec 26, 2001
27
*
Sep 14, 2001
Sep 14, 2001
28
29
30
31
32
33
* The basic gist of SDL_sound is that you use an SDL_RWops to get sound data
* into this library, and SDL_sound will take that data, in one of several
* popular formats, and decode it into raw waveform data in the format of
* your choice. This gives you a nice abstraction for getting sound into your
* game or application; just feed it to SDL_sound, and it will handle
* decoding and converting, so you can just pass it to your SDL audio
Sep 17, 2001
Sep 17, 2001
34
* callback (or whatever). Since it gets data from an SDL_RWops, you can get
Sep 14, 2001
Sep 14, 2001
35
36
37
38
39
40
41
42
* the initial sound data from any number of sources: file, memory buffer,
* network connection, etc.
*
* As the name implies, this library depends on SDL: Simple Directmedia Layer,
* which is a powerful, free, and cross-platform multimedia library. It can
* be found at http://www.libsdl.org/
*
* Support is in place or planned for the following sound formats:
Sep 17, 2001
Sep 17, 2001
43
44
* - .WAV (Microsoft WAVfile RIFF data, internal.)
* - .VOC (Creative Labs' Voice format, internal.)
Jan 30, 2009
Jan 30, 2009
45
* - .MP3 (MPEG-1 Layer 3 support, via libmpg123.)
Feb 8, 2002
Feb 8, 2002
46
47
* - .MID (MIDI music converted to Waveform data, internal.)
* - .MOD (MOD files, via MikMod and ModPlug.)
Sep 17, 2001
Sep 17, 2001
48
* - .OGG (Ogg files, via Ogg Vorbis libraries.)
Sep 13, 2003
Sep 13, 2003
49
* - .SPX (Speex files, via libspeex.)
Feb 8, 2002
Feb 8, 2002
50
* - .SHN (Shorten files, internal.)
Sep 17, 2001
Sep 17, 2001
51
* - .RAW (Raw sound data in any format, internal.)
Feb 8, 2002
Feb 8, 2002
52
53
54
* - .AU (Sun's Audio format, internal.)
* - .AIFF (Audio Interchange format, internal.)
* - .FLAC (Lossless audio compression, via libFLAC.)
Sep 14, 2001
Sep 14, 2001
55
56
57
*
* (...and more to come...)
*
Sep 9, 2008
Sep 9, 2008
58
* Please see the file LICENSE.txt in the source's root directory.
Sep 14, 2001
Sep 14, 2001
59
*
Aug 6, 2007
Aug 6, 2007
60
* \author Ryan C. Gordon (icculus@icculus.org)
Jun 7, 2002
Jun 7, 2002
61
* \author many others, please see CREDITS in the source's root directory.
Sep 14, 2001
Sep 14, 2001
62
63
*/
Sep 17, 2001
Sep 17, 2001
64
65
#ifndef _INCLUDE_SDL_SOUND_H_
#define _INCLUDE_SDL_SOUND_H_
Sep 14, 2001
Sep 14, 2001
66
67
#include "SDL.h"
Sep 19, 2001
Sep 19, 2001
68
#include "SDL_endian.h"
Sep 14, 2001
Sep 14, 2001
69
70
71
72
73
#ifdef __cplusplus
extern "C" {
#endif
Jun 7, 2002
Jun 7, 2002
74
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
Jul 5, 2002
Jul 5, 2002
75
76
77
78
79
#ifndef SDLCALL /* may not be defined with older SDL releases. */
#define SDLCALL
#endif
Oct 10, 2001
Oct 10, 2001
80
#ifdef SDL_SOUND_DLL_EXPORTS
Sep 26, 2002
Sep 26, 2002
81
# define SNDDECLSPEC __declspec(dllexport)
Aug 6, 2007
Aug 6, 2007
82
83
#elif (__GNUC__ >= 3)
# define SNDDECLSPEC __attribute__((visibility("default")))
Jul 5, 2002
Jul 5, 2002
84
#else
Sep 26, 2002
Sep 26, 2002
85
# define SNDDECLSPEC
Oct 10, 2001
Oct 10, 2001
86
87
#endif
Oct 9, 2002
Oct 9, 2002
88
89
#define SOUND_VER_MAJOR 1
#define SOUND_VER_MINOR 0
Oct 12, 2003
Oct 12, 2003
90
#define SOUND_VER_PATCH 1
Jun 7, 2002
Jun 7, 2002
91
#endif
Sep 19, 2001
Sep 19, 2001
92
93
Dec 26, 2001
Dec 26, 2001
94
/**
Jun 7, 2002
Jun 7, 2002
95
96
* \enum Sound_SampleFlags
* \brief Flags that are used in a Sound_Sample to show various states.
Sep 14, 2001
Sep 14, 2001
97
*
Jun 7, 2002
Jun 7, 2002
98
99
100
101
* To use:
* \code
* if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }
* \endcode
Jun 7, 2002
Jun 7, 2002
102
103
104
105
106
107
*
* \sa Sound_SampleNew
* \sa Sound_SampleNewFromFile
* \sa Sound_SampleDecode
* \sa Sound_SampleDecodeAll
* \sa Sound_SampleSeek
Sep 14, 2001
Sep 14, 2001
108
*/
Jun 7, 2002
Jun 7, 2002
109
typedef enum
Sep 14, 2001
Sep 14, 2001
110
{
Jun 7, 2002
Jun 7, 2002
111
SOUND_SAMPLEFLAG_NONE = 0, /**< No special attributes. */
Sep 14, 2001
Sep 14, 2001
112
113
/* these are set at sample creation time... */
Jun 7, 2002
Jun 7, 2002
114
SOUND_SAMPLEFLAG_CANSEEK = 1, /**< Sample can seek to arbitrary points. */
Sep 14, 2001
Sep 14, 2001
115
116
/* these are set during decoding... */
Jun 7, 2002
Jun 7, 2002
117
118
119
SOUND_SAMPLEFLAG_EOF = 1 << 29, /**< End of input stream. */
SOUND_SAMPLEFLAG_ERROR = 1 << 30, /**< Unrecoverable error. */
SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /**< Function would block, or temp error. */
Sep 14, 2001
Sep 14, 2001
120
121
122
} Sound_SampleFlags;
Dec 26, 2001
Dec 26, 2001
123
/**
Jun 7, 2002
Jun 7, 2002
124
125
126
* \struct Sound_AudioInfo
* \brief Information about an existing sample's format.
*
Dec 26, 2001
Dec 26, 2001
127
128
129
130
* These are the basics of a decoded sample's data structure: data format
* (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample
* rate. If you need more explanation than that, you should stop developing
* sound code right now.
Jun 7, 2002
Jun 7, 2002
131
132
133
*
* \sa Sound_SampleNew
* \sa Sound_SampleNewFromFile
Sep 17, 2001
Sep 17, 2001
134
*/
Jun 7, 2002
Jun 7, 2002
135
typedef struct
Sep 17, 2001
Sep 17, 2001
136
{
Jun 7, 2002
Jun 7, 2002
137
138
139
Uint16 format; /**< Equivalent of SDL_AudioSpec.format. */
Uint8 channels; /**< Number of sound channels. 1 == mono, 2 == stereo. */
Uint32 rate; /**< Sample rate; frequency of sample points per second. */
Sep 17, 2001
Sep 17, 2001
140
141
142
} Sound_AudioInfo;
Dec 26, 2001
Dec 26, 2001
143
/**
Jun 7, 2002
Jun 7, 2002
144
145
146
* \struct Sound_DecoderInfo
* \brief Information about available soudn decoders.
*
Sep 17, 2001
Sep 17, 2001
147
148
* Each decoder sets up one of these structs, which can be retrieved via
* the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY.
Dec 26, 2001
Dec 26, 2001
149
*
Jun 7, 2002
Jun 7, 2002
150
151
152
153
154
155
156
157
158
159
* The extensions field is a NULL-terminated list of ASCIZ strings. You
* should read it like this:
*
* \code
* const char **ext;
* for (ext = info->extensions; *ext != NULL; ext++) {
* printf(" File extension \"%s\"\n", *ext);
* }
* \endcode
*
Jun 7, 2002
Jun 7, 2002
160
* \sa Sound_AvailableDecoders
Sep 17, 2001
Sep 17, 2001
161
*/
Jun 7, 2002
Jun 7, 2002
162
typedef struct
Sep 17, 2001
Sep 17, 2001
163
{
Jun 7, 2002
Jun 7, 2002
164
165
166
167
const char **extensions; /**< File extensions, list ends with NULL. */
const char *description; /**< Human readable description of decoder. */
const char *author; /**< "Name Of Author \<email@emailhost.dom\>" */
const char *url; /**< URL specific to this decoder. */
Sep 17, 2001
Sep 17, 2001
168
169
170
171
} Sound_DecoderInfo;
Dec 26, 2001
Dec 26, 2001
172
/**
Jun 7, 2002
Jun 7, 2002
173
174
175
* \struct Sound_Sample
* \brief Represents sound data in the process of being decoded.
*
Sep 14, 2001
Sep 14, 2001
176
177
178
179
180
* The Sound_Sample structure is the heart of SDL_sound. This holds
* information about a source of sound data as it is being decoded.
* EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to
* change them.
*/
Jun 7, 2002
Jun 7, 2002
181
typedef struct
Sep 14, 2001
Sep 14, 2001
182
{
Jun 7, 2002
Jun 7, 2002
183
184
185
186
187
188
189
void *opaque; /**< Internal use only. Don't touch. */
const Sound_DecoderInfo *decoder; /**< Decoder used for this sample. */
Sound_AudioInfo desired; /**< Desired audio format for conversion. */
Sound_AudioInfo actual; /**< Actual audio format of sample. */
void *buffer; /**< Decoded sound data lands in here. */
Uint32 buffer_size; /**< Current size of (buffer), in bytes (Uint8). */
Sound_SampleFlags flags; /**< Flags relating to this sample. */
Sep 14, 2001
Sep 14, 2001
190
191
192
} Sound_Sample;
Dec 26, 2001
Dec 26, 2001
193
/**
Jun 7, 2002
Jun 7, 2002
194
195
196
197
198
199
200
201
* \struct Sound_Version
* \brief Information the version of SDL_sound in use.
*
* Represents the library's version as three levels: major revision
* (increments with massive changes, additions, and enhancements),
* minor revision (increments with backwards-compatible changes to the
* major revision), and patchlevel (increments with fixes to the minor
* revision).
Dec 26, 2001
Dec 26, 2001
202
*
Jun 7, 2002
Jun 7, 2002
203
204
* \sa SOUND_VERSION
* \sa Sound_GetLinkedVersion
Sep 14, 2001
Sep 14, 2001
205
*/
Jun 7, 2002
Jun 7, 2002
206
typedef struct
Sep 14, 2001
Sep 14, 2001
207
{
Jun 7, 2002
Jun 7, 2002
208
209
210
int major; /**< major revision */
int minor; /**< minor revision */
int patch; /**< patchlevel */
Sep 14, 2001
Sep 14, 2001
211
212
213
214
215
} Sound_Version;
/* functions and macros... */
Jun 7, 2002
Jun 7, 2002
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* \def SOUND_VERSION(x)
* \brief Macro to determine SDL_sound version program was compiled against.
*
* This macro fills in a Sound_Version structure with the version of the
* library you compiled against. This is determined by what header the
* compiler uses. Note that if you dynamically linked the library, you might
* have a slightly newer or older version at runtime. That version can be
* determined with Sound_GetLinkedVersion(), which, unlike SOUND_VERSION,
* is not a macro.
*
* \param x A pointer to a Sound_Version struct to initialize.
*
* \sa Sound_Version
* \sa Sound_GetLinkedVersion
*/
#define SOUND_VERSION(x) \
{ \
(x)->major = SOUND_VER_MAJOR; \
(x)->minor = SOUND_VER_MINOR; \
(x)->patch = SOUND_VER_PATCH; \
}
Sep 14, 2001
Sep 14, 2001
239
240
/**
Jun 7, 2002
Jun 7, 2002
241
242
243
244
245
* \fn void Sound_GetLinkedVersion(Sound_Version *ver)
* \brief Get the version of SDL_sound that is linked against your program.
*
* If you are using a shared library (DLL) version of SDL_sound, then it is
* possible that it will be different than the version you compiled against.
Sep 14, 2001
Sep 14, 2001
246
*
Sep 17, 2001
Sep 17, 2001
247
* This is a real function; the macro SOUND_VERSION tells you what version
Sep 14, 2001
Sep 14, 2001
248
249
* of SDL_sound you compiled against:
*
Jun 7, 2002
Jun 7, 2002
250
* \code
Sep 14, 2001
Sep 14, 2001
251
252
253
* Sound_Version compiled;
* Sound_Version linked;
*
Sep 17, 2001
Sep 17, 2001
254
* SOUND_VERSION(&compiled);
Sep 14, 2001
Sep 14, 2001
255
256
257
258
259
* Sound_GetLinkedVersion(&linked);
* printf("We compiled against SDL_sound version %d.%d.%d ...\n",
* compiled.major, compiled.minor, compiled.patch);
* printf("But we linked against SDL_sound version %d.%d.%d.\n",
* linked.major, linked.minor, linked.patch);
Jun 7, 2002
Jun 7, 2002
260
* \endcode
Sep 14, 2001
Sep 14, 2001
261
262
*
* This function may be called safely at any time, even before Sound_Init().
Dec 26, 2001
Dec 26, 2001
263
*
Jun 7, 2002
Jun 7, 2002
264
* \param ver Sound_Version structure to fill with shared library's version.
Jun 7, 2002
Jun 7, 2002
265
266
267
*
* \sa Sound_Version
* \sa SOUND_VERSION
Sep 14, 2001
Sep 14, 2001
268
*/
Sep 26, 2002
Sep 26, 2002
269
SNDDECLSPEC void SDLCALL Sound_GetLinkedVersion(Sound_Version *ver);
Sep 14, 2001
Sep 14, 2001
270
271
272
/**
Jun 7, 2002
Jun 7, 2002
273
274
275
276
277
278
279
280
* \fn Sound_Init(void)
* \brief Initialize SDL_sound.
*
* This must be called before any other SDL_sound function (except perhaps
* Sound_GetLinkedVersion()). You should call SDL_Init() before calling this.
* Sound_Init() will attempt to call SDL_Init(SDL_INIT_AUDIO), just in case.
* This is a safe behaviour, but it may not configure SDL to your liking by
* itself.
Sep 14, 2001
Sep 14, 2001
281
*
Jun 7, 2002
Jun 7, 2002
282
283
284
285
* \return nonzero on success, zero on error. Specifics of the
* error can be gleaned from Sound_GetError().
*
* \sa Sound_Quit
Sep 14, 2001
Sep 14, 2001
286
*/
Sep 26, 2002
Sep 26, 2002
287
SNDDECLSPEC int SDLCALL Sound_Init(void);
Sep 14, 2001
Sep 14, 2001
288
289
290
/**
Jun 7, 2002
Jun 7, 2002
291
292
293
294
295
* \fn Sound_Quit(void)
* \brief Shutdown SDL_sound.
*
* This closes any SDL_RWops that were being used as sound sources, and frees
* any resources in use by SDL_sound.
Sep 14, 2001
Sep 14, 2001
296
297
298
299
*
* All Sound_Sample pointers you had prior to this call are INVALIDATED.
*
* Once successfully deinitialized, Sound_Init() can be called again to
Sep 17, 2001
Sep 17, 2001
300
* restart the subsystem. All default API states are restored at this
Sep 14, 2001
Sep 14, 2001
301
302
303
304
305
* point.
*
* You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit()
* for you!
*
Jun 7, 2002
Jun 7, 2002
306
* \return nonzero on success, zero on error. Specifics of the error
Jun 7, 2002
Jun 7, 2002
307
308
309
310
* can be gleaned from Sound_GetError(). If failure, state of
* SDL_sound is undefined, and probably badly screwed up.
*
* \sa Sound_Init
Sep 14, 2001
Sep 14, 2001
311
*/
Sep 26, 2002
Sep 26, 2002
312
SNDDECLSPEC int SDLCALL Sound_Quit(void);
Sep 14, 2001
Sep 14, 2001
313
314
315
/**
Jun 7, 2002
Jun 7, 2002
316
317
318
319
* \fn const Sound_DecoderInfo **Sound_AvailableDecoders(void)
* \brief Get a list of sound formats supported by this version of SDL_sound.
*
* This is for informational purposes only. Note that the extension listed is
Sep 18, 2001
Sep 18, 2001
320
* merely convention: if we list "MP3", you can open an MPEG-1 Layer 3 audio
Sep 14, 2001
Sep 14, 2001
321
322
323
324
325
326
327
328
* file with an extension of "XYZ", if you like. The file extensions are
* informational, and only required as a hint to choosing the correct
* decoder, since the sound data may not be coming from a file at all, thanks
* to the abstraction that an SDL_RWops provides.
*
* The returned value is an array of pointers to Sound_DecoderInfo structures,
* with a NULL entry to signify the end of the list:
*
Jun 7, 2002
Jun 7, 2002
329
* \code
Sep 14, 2001
Sep 14, 2001
330
331
332
333
334
335
336
337
* Sound_DecoderInfo **i;
*
* for (i = Sound_AvailableDecoders(); *i != NULL; i++)
* {
* printf("Supported sound format: [%s], which is [%s].\n",
* i->extension, i->description);
* // ...and other fields...
* }
Jun 7, 2002
Jun 7, 2002
338
* \endcode
Sep 14, 2001
Sep 14, 2001
339
340
341
342
*
* The return values are pointers to static internal memory, and should
* be considered READ ONLY, and never freed.
*
Jun 7, 2002
Jun 7, 2002
343
344
345
* \return READ ONLY Null-terminated array of READ ONLY structures.
*
* \sa Sound_DecoderInfo
Sep 14, 2001
Sep 14, 2001
346
*/
Sep 26, 2002
Sep 26, 2002
347
SNDDECLSPEC const Sound_DecoderInfo ** SDLCALL Sound_AvailableDecoders(void);
Sep 14, 2001
Sep 14, 2001
348
349
350
/**
Jun 7, 2002
Jun 7, 2002
351
352
353
354
355
356
357
358
359
360
* \fn const char *Sound_GetError(void)
* \brief Get the last SDL_sound error message as a null-terminated string.
*
* This will be NULL if there's been no error since the last call to this
* function. The pointer returned by this call points to an internal buffer,
* and should not be deallocated. Each thread has a unique error state
* associated with it, but each time a new error message is set, it will
* overwrite the previous one associated with that thread. It is safe to call
* this function at anytime, even before Sound_Init().
*
Jun 7, 2002
Jun 7, 2002
361
362
363
* \return READ ONLY string of last error message.
*
* \sa Sound_ClearError
Sep 14, 2001
Sep 14, 2001
364
*/
Sep 26, 2002
Sep 26, 2002
365
SNDDECLSPEC const char * SDLCALL Sound_GetError(void);
Sep 17, 2001
Sep 17, 2001
366
367
368
/**
Jun 7, 2002
Jun 7, 2002
369
370
371
372
* \fn void Sound_ClearError(void)
* \brief Clear the current error message.
*
* The next call to Sound_GetError() after Sound_ClearError() will return NULL.
Jun 7, 2002
Jun 7, 2002
373
374
*
* \sa Sound_GetError
Sep 17, 2001
Sep 17, 2001
375
*/
Sep 26, 2002
Sep 26, 2002
376
SNDDECLSPEC void SDLCALL Sound_ClearError(void);
Sep 14, 2001
Sep 14, 2001
377
378
379
/**
Jun 7, 2002
Jun 7, 2002
380
381
382
383
384
385
386
387
388
389
390
391
392
393
* \fn Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, Sound_AudioInfo *desired, Uint32 bufferSize)
* \brief Start decoding a new sound sample.
*
* The data is read via an SDL_RWops structure (see SDL_rwops.h in the SDL
* include directory), so it may be coming from memory, disk, network stream,
* etc. The (ext) parameter is merely a hint to determining the correct
* decoder; if you specify, for example, "mp3" for an extension, and one of
* the decoders lists that as a handled extension, then that decoder is given
* first shot at trying to claim the data for decoding. If none of the
* extensions match (or the extension is NULL), then every decoder examines
* the data to determine if it can handle it, until one accepts it. In such a
* case your SDL_RWops will need to be capable of rewinding to the start of
* the stream.
*
Sep 14, 2001
Sep 14, 2001
394
* If no decoders can handle the data, a NULL value is returned, and a human
Dec 27, 2001
Dec 27, 2001
395
* readable error message can be fetched from Sound_GetError().
Jun 7, 2002
Jun 7, 2002
396
*
Sep 14, 2001
Sep 14, 2001
397
398
399
400
401
402
403
404
* Optionally, a desired audio format can be specified. If the incoming data
* is in a different format, SDL_sound will convert it to the desired format
* on the fly. Note that this can be an expensive operation, so it may be
* wise to convert data before you need to play it back, if possible, or
* make sure your data is initially in the format that you need it in.
* If you don't want to convert the data, you can specify NULL for a desired
* format. The incoming format of the data, preconversion, can be found
* in the Sound_Sample structure.
Jun 7, 2002
Jun 7, 2002
405
*
Sep 14, 2001
Sep 14, 2001
406
* Note that the raw sound data "decoder" needs you to specify both the
Sep 17, 2001
Sep 17, 2001
407
408
409
* extension "RAW" and a "desired" format, or it will refuse to handle
* the data. This is to prevent it from catching all formats unsupported
* by the other decoders.
Jun 7, 2002
Jun 7, 2002
410
*
Sep 14, 2001
Sep 14, 2001
411
412
413
414
415
416
* Finally, specify an initial buffer size; this is the number of bytes that
* will be allocated to store each read from the sound buffer. The more you
* can safely allocate, the more decoding can be done in one block, but the
* more resources you have to use up, and the longer each decoding call will
* take. Note that different data formats require more or less space to
* store. This buffer can be resized via Sound_SetBufferSize() ...
Jun 7, 2002
Jun 7, 2002
417
*
Sep 17, 2001
Sep 17, 2001
418
* The buffer size specified must be a multiple of the size of a single
Dec 27, 2001
Dec 27, 2001
419
420
421
422
423
* sample point. So, if you want 16-bit, stereo samples, then your sample
* point size is (2 channels * 16 bits), or 32 bits per sample, which is four
* bytes. In such a case, you could specify 128 or 132 bytes for a buffer,
* but not 129, 130, or 131 (although in reality, you'll want to specify a
* MUCH larger buffer).
Jun 7, 2002
Jun 7, 2002
424
*
Sep 14, 2001
Sep 14, 2001
425
426
* When you are done with this Sound_Sample pointer, you can dispose of it
* via Sound_FreeSample().
Jun 7, 2002
Jun 7, 2002
427
*
Sep 17, 2001
Sep 17, 2001
428
429
430
431
* You do not have to keep a reference to (rw) around. If this function
* suceeds, it stores (rw) internally (and disposes of it during the call
* to Sound_FreeSample()). If this function fails, it will dispose of the
* SDL_RWops for you.
Sep 14, 2001
Sep 14, 2001
432
*
Jun 7, 2002
Jun 7, 2002
433
434
* \param rw SDL_RWops with sound data.
* \param ext File extension normally associated with a data format.
Sep 14, 2001
Sep 14, 2001
435
* Can usually be NULL.
Jun 7, 2002
Jun 7, 2002
436
* \param desired Format to convert sound data into. Can usually be NULL,
Sep 14, 2001
Sep 14, 2001
437
* if you don't need conversion.
Jun 7, 2002
Jun 7, 2002
438
439
* \param bufferSize Size, in bytes, to allocate for the decoding buffer.
* \return Sound_Sample pointer, which is used as a handle to several other
Jun 7, 2002
Jun 7, 2002
440
441
442
443
444
445
446
447
448
449
* SDL_sound APIs. NULL on error. If error, use
* Sound_GetError() to see what went wrong.
*
* \sa Sound_NewSampleFromFile
* \sa Sound_SetBufferSize
* \sa Sound_Decode
* \sa Sound_DecodeAll
* \sa Sound_Seek
* \sa Sound_Rewind
* \sa Sound_FreeSample
Sep 14, 2001
Sep 14, 2001
450
*/
Sep 26, 2002
Sep 26, 2002
451
452
453
454
SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSample(SDL_RWops *rw,
const char *ext,
Sound_AudioInfo *desired,
Uint32 bufferSize);
Sep 14, 2001
Sep 14, 2001
455
Feb 27, 2005
Feb 27, 2005
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/**
* \fn Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data, Sound_AudioInfo *desired, Uint32 bufferSize)
* \brief Start decoding a new sound sample from a file on disk.
*
* This is identical to Sound_NewSample(), but it creates an SDL_RWops for you
* from the (size) bytes of memory referenced by (data).
*
* This can pool RWops structures, so it may fragment the heap less over time
* than using SDL_RWFromMem().
*
* \param filename file containing sound data.
* \param desired Format to convert sound data into. Can usually be NULL,
* if you don't need conversion.
* \param bufferSize size, in bytes, of initial read buffer.
* \return Sound_Sample pointer, which is used as a handle to several other
* SDL_sound APIs. NULL on error. If error, use
* Sound_GetError() to see what went wrong.
*
* \sa Sound_NewSample
* \sa Sound_SetBufferSize
* \sa Sound_Decode
* \sa Sound_DecodeAll
* \sa Sound_Seek
* \sa Sound_Rewind
* \sa Sound_FreeSample
*/
SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSampleFromMem(const Uint8 *data,
Uint32 size,
const char *ext,
Sound_AudioInfo *desired,
Uint32 bufferSize);
Sep 17, 2001
Sep 17, 2001
489
/**
Jun 7, 2002
Jun 7, 2002
490
491
492
* \fn Sound_Sample *Sound_NewSampleFromFile(const char *filename, Sound_AudioInfo *desired, Uint32 bufferSize)
* \brief Start decoding a new sound sample from a file on disk.
*
Sep 17, 2001
Sep 17, 2001
493
494
495
496
497
498
499
* This is identical to Sound_NewSample(), but it creates an SDL_RWops for you
* from the file located in (filename). Note that (filename) is specified in
* platform-dependent notation. ("C:\\music\\mysong.mp3" on windows, and
* "/home/icculus/music/mysong.mp3" or whatever on Unix, etc.)
* Sound_NewSample()'s "ext" parameter is gleaned from the contents of
* (filename).
*
Feb 27, 2005
Feb 27, 2005
500
501
502
* This can pool RWops structures, so it may fragment the heap less over time
* than using SDL_RWFromFile().
*
Jun 7, 2002
Jun 7, 2002
503
504
* \param filename file containing sound data.
* \param desired Format to convert sound data into. Can usually be NULL,
Sep 17, 2001
Sep 17, 2001
505
* if you don't need conversion.
Jun 7, 2002
Jun 7, 2002
506
507
* \param bufferSize size, in bytes, of initial read buffer.
* \return Sound_Sample pointer, which is used as a handle to several other
Jun 7, 2002
Jun 7, 2002
508
509
510
511
512
513
514
515
516
517
* SDL_sound APIs. NULL on error. If error, use
* Sound_GetError() to see what went wrong.
*
* \sa Sound_NewSample
* \sa Sound_SetBufferSize
* \sa Sound_Decode
* \sa Sound_DecodeAll
* \sa Sound_Seek
* \sa Sound_Rewind
* \sa Sound_FreeSample
Sep 17, 2001
Sep 17, 2001
518
*/
Sep 26, 2002
Sep 26, 2002
519
SNDDECLSPEC Sound_Sample * SDLCALL Sound_NewSampleFromFile(const char *fname,
Sep 17, 2001
Sep 17, 2001
520
521
522
Sound_AudioInfo *desired,
Uint32 bufferSize);
Sep 14, 2001
Sep 14, 2001
523
/**
Jun 7, 2002
Jun 7, 2002
524
* \fn void Sound_FreeSample(Sound_Sample *sample)
Jul 10, 2002
Jul 10, 2002
525
* \brief Dispose of a Sound_Sample.
Jun 7, 2002
Jun 7, 2002
526
527
*
* This will also close/dispose of the SDL_RWops that was used at creation
Sep 14, 2001
Sep 14, 2001
528
529
530
531
* time, so there's no need to keep a reference to that around.
* The Sound_Sample pointer is invalid after this call, and will almost
* certainly result in a crash if you attempt to keep using it.
*
Jun 7, 2002
Jun 7, 2002
532
* \param sample The Sound_Sample to delete.
Jun 7, 2002
Jun 7, 2002
533
534
535
*
* \sa Sound_NewSample
* \sa Sound_NewSampleFromFile
Sep 14, 2001
Sep 14, 2001
536
*/
Sep 26, 2002
Sep 26, 2002
537
SNDDECLSPEC void SDLCALL Sound_FreeSample(Sound_Sample *sample);
Sep 14, 2001
Sep 14, 2001
538
539
May 12, 2004
May 12, 2004
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/**
* \fn Sint32 Sound_GetDuration(Sound_Sample *sample)
* \brief Retrieve total play time of sample, in milliseconds.
*
* Report total time length of sample, in milliseconds. This is a fast
* call. Duration is calculated during Sound_NewSample*, so this is just
* an accessor into otherwise opaque data.
*
* Please note that not all formats can determine a total time, some can't
* be exact without fully decoding the data, and thus will estimate the
* duration. Many decoders will require the ability to seek in the data
* stream to calculate this, so even if we can tell you how long an .ogg
* file will be, the same data set may fail if it's, say, streamed over an
* HTTP connection. Plan accordingly.
*
* Most people won't need this function to just decode and playback, but it
* can be useful for informational purposes in, say, a music player's UI.
*
* \param sample Sound_Sample from which to retrieve duration information.
* \return Sample length in milliseconds, or -1 if duration can't be
* determined for any reason.
*/
SNDDECLSPEC Sint32 SDLCALL Sound_GetDuration(Sound_Sample *sample);
Sep 17, 2001
Sep 17, 2001
565
/**
Jun 7, 2002
Jun 7, 2002
566
567
568
569
570
571
572
573
574
* \fn int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size)
* \brief Change the current buffer size for a sample.
*
* If the buffer size could be changed, then the sample->buffer and
* sample->buffer_size fields will reflect that. If they could not be
* changed, then your original sample state is preserved. If the buffer is
* shrinking, the data at the end of buffer is truncated. If the buffer is
* growing, the contents of the new space at the end is undefined until you
* decode more into it or initialize it yourself.
Sep 17, 2001
Sep 17, 2001
575
576
*
* The buffer size specified must be a multiple of the size of a single
Dec 27, 2001
Dec 27, 2001
577
578
579
580
581
* sample point. So, if you want 16-bit, stereo samples, then your sample
* point size is (2 channels * 16 bits), or 32 bits per sample, which is four
* bytes. In such a case, you could specify 128 or 132 bytes for a buffer,
* but not 129, 130, or 131 (although in reality, you'll want to specify a
* MUCH larger buffer).
Sep 17, 2001
Sep 17, 2001
582
*
Jun 7, 2002
Jun 7, 2002
583
584
585
* \param sample The Sound_Sample whose buffer to modify.
* \param new_size The desired size, in bytes, of the new buffer.
* \return non-zero if buffer size changed, zero on failure.
Jun 7, 2002
Jun 7, 2002
586
587
588
*
* \sa Sound_Decode
* \sa Sound_DecodeAll
Sep 17, 2001
Sep 17, 2001
589
*/
Sep 26, 2002
Sep 26, 2002
590
591
SNDDECLSPEC int SDLCALL Sound_SetBufferSize(Sound_Sample *sample,
Uint32 new_size);
Sep 17, 2001
Sep 17, 2001
592
593
Sep 14, 2001
Sep 14, 2001
594
/**
Jun 7, 2002
Jun 7, 2002
595
596
597
598
599
* \fn Uint32 Sound_Decode(Sound_Sample *sample)
* \brief Decode more of the sound data in a Sound_Sample.
*
* It will decode at most sample->buffer_size bytes into sample->buffer in the
* desired format, and return the number of decoded bytes.
Sep 14, 2001
Sep 14, 2001
600
* If sample->buffer_size bytes could not be decoded, then please refer to
Jun 7, 2002
Jun 7, 2002
601
* sample->flags to determine if this was an end-of-stream or error condition.
Sep 14, 2001
Sep 14, 2001
602
*
Jun 7, 2002
Jun 7, 2002
603
604
* \param sample Do more decoding to this Sound_Sample.
* \return number of bytes decoded into sample->buffer. If it is less than
Sep 14, 2001
Sep 14, 2001
605
606
* sample->buffer_size, then you should check sample->flags to see
* what the current state of the sample is (EOF, error, read again).
Jun 7, 2002
Jun 7, 2002
607
608
609
610
611
*
* \sa Sound_DecodeAll
* \sa Sound_SetBufferSize
* \sa Sound_Seek
* \sa Sound_Rewind
Sep 14, 2001
Sep 14, 2001
612
*/
Sep 26, 2002
Sep 26, 2002
613
SNDDECLSPEC Uint32 SDLCALL Sound_Decode(Sound_Sample *sample);
Sep 14, 2001
Sep 14, 2001
614
615
616
/**
Jun 7, 2002
Jun 7, 2002
617
618
619
620
* \fn Uint32 Sound_DecodeAll(Sound_Sample *sample)
* \brief Decode the remainder of the sound data in a Sound_Sample.
*
* This will dynamically allocate memory for the ENTIRE remaining sample.
Sep 14, 2001
Sep 14, 2001
621
622
623
624
625
626
627
628
629
630
631
* sample->buffer_size and sample->buffer will be updated to reflect the
* new buffer. Please refer to sample->flags to determine if the decoding
* finished due to an End-of-stream or error condition.
*
* Be aware that sound data can take a large amount of memory, and that
* this function may block for quite awhile while processing. Also note
* that a streaming source (for example, from a SDL_RWops that is getting
* fed from an Internet radio feed that doesn't end) may fill all available
* memory before giving up...be sure to use this on finite sound sources
* only!
*
Nov 26, 2001
Nov 26, 2001
632
633
634
635
636
637
638
639
640
* When decoding the sample in its entirety, the work is done one buffer at a
* time. That is, sound is decoded in sample->buffer_size blocks, and
* appended to a continually-growing buffer until the decoding completes.
* That means that this function will need enough RAM to hold approximately
* sample->buffer_size bytes plus the complete decoded sample at most. The
* larger your buffer size, the less overhead this function needs, but beware
* the possibility of paging to disk. Best to make this user-configurable if
* the sample isn't specific and small.
*
Jun 7, 2002
Jun 7, 2002
641
642
* \param sample Do all decoding for this Sound_Sample.
* \return number of bytes decoded into sample->buffer. You should check
Nov 26, 2001
Nov 26, 2001
643
644
* sample->flags to see what the current state of the sample is
* (EOF, error, read again).
Jun 7, 2002
Jun 7, 2002
645
646
647
*
* \sa Sound_Decode
* \sa Sound_SetBufferSize
Sep 14, 2001
Sep 14, 2001
648
*/
Sep 26, 2002
Sep 26, 2002
649
SNDDECLSPEC Uint32 SDLCALL Sound_DecodeAll(Sound_Sample *sample);
Jun 7, 2002
Jun 7, 2002
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/**
* \fn int Sound_Rewind(Sound_Sample *sample)
* \brief Rewind a sample to the start.
*
* Restart a sample at the start of its waveform data, as if newly
* created with Sound_NewSample(). If successful, the next call to
* Sound_Decode[All]() will give audio data from the earliest point
* in the stream.
*
* Beware that this function will fail if the SDL_RWops that feeds the
* decoder can not be rewound via it's seek method, but this can
* theoretically be avoided by wrapping it in some sort of buffering
* SDL_RWops.
*
* This function should ONLY fail if the RWops is not seekable, or
* SDL_sound is not initialized. Both can be controlled by the application,
* and thus, it is up to the developer's paranoia to dictate whether this
* function's return value need be checked at all.
*
* If this function fails, the state of the sample is undefined, but it
* is still safe to call Sound_FreeSample() to dispose of it.
*
* On success, ERROR, EOF, and EAGAIN are cleared from sample->flags. The
* ERROR flag is set on error.
*
* \param sample The Sound_Sample to rewind.
* \return nonzero on success, zero on error. Specifics of the
* error can be gleaned from Sound_GetError().
Jun 7, 2002
Jun 7, 2002
680
681
*
* \sa Sound_Seek
Jun 7, 2002
Jun 7, 2002
682
*/
Sep 26, 2002
Sep 26, 2002
683
SNDDECLSPEC int SDLCALL Sound_Rewind(Sound_Sample *sample);
Jun 7, 2002
Jun 7, 2002
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/**
* \fn int Sound_Seek(Sound_Sample *sample, Uint32 ms)
* \brief Seek to a different point in a sample.
*
* Reposition a sample's stream. If successful, the next call to
* Sound_Decode[All]() will give audio data from the offset you
* specified.
*
* The offset is specified in milliseconds from the start of the
* sample.
*
* Beware that this function can fail for several reasons. If the
* SDL_RWops that feeds the decoder can not seek, this call will almost
* certainly fail, but this can theoretically be avoided by wrapping it
* in some sort of buffering SDL_RWops. Some decoders can never seek,
* others can only seek with certain files. The decoders will set a flag
* in the sample at creation time to help you determine this.
*
* You should check sample->flags & SOUND_SAMPLEFLAG_CANSEEK
* before attempting. Sound_Seek() reports failure immediately if this
* flag isn't set. This function can still fail for other reasons if the
* flag is set.
*
* This function can be emulated in the application with Sound_Rewind()
* and predecoding a specific amount of the sample, but this can be
* extremely inefficient. Sound_Seek() accelerates the seek on a
* with decoder-specific code.
*
* If this function fails, the sample should continue to function as if
* this call was never made. If there was an unrecoverable error,
* sample->flags & SOUND_SAMPLEFLAG_ERROR will be set, which you regular
* decoding loop can pick up.
*
* On success, ERROR, EOF, and EAGAIN are cleared from sample->flags.
*
* \param sample The Sound_Sample to seek.
* \param ms The new position, in milliseconds from start of sample.
* \return nonzero on success, zero on error. Specifics of the
* error can be gleaned from Sound_GetError().
Jun 7, 2002
Jun 7, 2002
725
726
*
* \sa Sound_Rewind
Jun 7, 2002
Jun 7, 2002
727
*/
Sep 26, 2002
Sep 26, 2002
728
SNDDECLSPEC int SDLCALL Sound_Seek(Sound_Sample *sample, Uint32 ms);
Apr 21, 2002
Apr 21, 2002
729
Sep 14, 2001
Sep 14, 2001
730
731
732
733
#ifdef __cplusplus
}
#endif
Sep 17, 2001
Sep 17, 2001
734
#endif /* !defined _INCLUDE_SDL_SOUND_H_ */
Sep 14, 2001
Sep 14, 2001
735
736
/* end of SDL_sound.h ... */