annotate SDL_sound.h @ 140:c28566f219e2 release-0.1.3

Updated.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 15 Oct 2001 18:26:27 +0000
parents ac49f81e42d6
children 1df5c106504e
rev   line source
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 * into this library, and SDL_sound will take that data, in one of several
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * popular formats, and decode it into raw waveform data in the format of
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * your choice. This gives you a nice abstraction for getting sound into your
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * game or application; just feed it to SDL_sound, and it will handle
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * the initial sound data from any number of sources: file, memory buffer,
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * network connection, etc.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 * As the name implies, this library depends on SDL: Simple Directmedia Layer,
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 * which is a powerful, free, and cross-platform multimedia library. It can
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 * be found at http://www.libsdl.org/
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
Ryan C. Gordon <icculus@icculus.org>
parents: 3
diff changeset
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
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 * (...and more to come...)
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 * Please see the file LICENSE in the source's root directory.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
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
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 #ifdef __cplusplus
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 extern "C" {
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 #endif
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63
130
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
64 #ifdef SDL_SOUND_DLL_EXPORTS
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
65 # undef DECLSPEC
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
66 # define DECLSPEC __declspec(dllexport)
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
67 #endif
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
68
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
69
29
0e27c909c952 Upped version to 0.1.1
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
70 #define SOUND_VER_MAJOR 0
0e27c909c952 Upped version to 0.1.1
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
71 #define SOUND_VER_MINOR 1
130
ac49f81e42d6 Win32 fix, upped version to 0.1.3.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
72 #define SOUND_VER_PATCH 3
29
0e27c909c952 Upped version to 0.1.1
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
73
0e27c909c952 Upped version to 0.1.1
Ryan C. Gordon <icculus@icculus.org>
parents: 19
diff changeset
74
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 /*
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 * These are flags that are used in a Sound_Sample (below) to show various
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 * states.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 *
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
79 * To use: "if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }"
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 */
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
81 typedef enum __SOUND_SAMPLEFLAGS__
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 {
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
83 SOUND_SAMPLEFLAG_NONE = 0, /* Null flag. */
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 /* 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
86 SOUND_SAMPLEFLAG_NEEDSEEK = 1, /* SDL_RWops must be able to seek. */
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 /* these are set during decoding... */
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
89 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
90 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /* unrecoverable error. */
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
91 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /* would block, or temp error. */
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 } Sound_SampleFlags;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 /*
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
96 * 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
97 * 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
98 * 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
99 * now.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
100 */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
101 typedef struct __SOUND_AUDIOINFO__
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 Uint16 format;
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
104 Uint8 channels;
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
105 Uint32 rate;
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
106 } Sound_AudioInfo;
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
107
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 /*
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
110 * 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
111 * 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
112 */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
113 typedef struct __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 const char *extension; /* standard file extension. "MP3", "WAV"... */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
116 const char *description; /* Human readable description of decoder. */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
117 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
118 const char *url; /* URL specific to this decoder. */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
119 } Sound_DecoderInfo;
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
120
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
121
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
122
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
123 /*
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 * The Sound_Sample structure is the heart of SDL_sound. This holds
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 * information about a source of sound data as it is being decoded.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 * change them.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 */
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
129 typedef struct __SOUND_SAMPLE__
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 {
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 void *opaque; /* Internal use only. */
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
132 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
133 Sound_AudioInfo desired; /* Desired audio format for conversion. */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
134 Sound_AudioInfo actual; /* Actual audio format of sample. */
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 void *buffer; /* Decoded sound data lands in here. */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 Uint32 buffer_size; /* Current size of (buffer), in bytes. */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 Sound_SampleFlags flags; /* Flags relating to this sample. */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 } Sound_Sample;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 /*
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 * Just what it says: a x.y.z style version number...
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 */
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
144 typedef struct __SOUND_VERSION__
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 {
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 int major;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 int minor;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 int patch;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 } Sound_Version;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 /* functions and macros... */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
155 #define SOUND_VERSION(x) { \
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
156 (x)->major = SOUND_VER_MAJOR; \
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
157 (x)->minor = SOUND_VER_MINOR; \
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
158 (x)->patch = SOUND_VER_PATCH; \
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 }
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 * Get the version of SDL_sound that is linked against your program. If you
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 * are using a shared library (DLL) version of SDL_sound, then it is possible
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 * that it will be different than the version you compiled against.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 *
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
166 * This is a real function; the macro SOUND_VERSION tells you what version
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 * of SDL_sound you compiled against:
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 * Sound_Version compiled;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 * Sound_Version linked;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 *
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
172 * SOUND_VERSION(&compiled);
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 * Sound_GetLinkedVersion(&linked);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 * printf("We compiled against SDL_sound version %d.%d.%d ...\n",
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 * compiled.major, compiled.minor, compiled.patch);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 * printf("But we linked against SDL_sound version %d.%d.%d.\n",
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 * linked.major, linked.minor, linked.patch);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 * This function may be called safely at any time, even before Sound_Init().
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 extern DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 * Initialize SDL_sound. This must be called before any other SDL_sound
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 * function (except perhaps Sound_GetLinkedVersion()). You should call
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 * SDL_Init() before calling this. Sound_Init() will attempt to call
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 * SDL_Init(SDL_INIT_AUDIO), just in case. This is a safe behaviour, but it
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 * may not configure SDL to your liking by itself.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 * @return nonzero on success, zero on error. Specifics of the error can be
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 * gleaned from Sound_GetLastError().
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 extern DECLSPEC int Sound_Init(void);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 * Shutdown SDL_sound. This closes any SDL_RWops that were being used as
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 * sound sources, and frees any resources in use by SDL_sound.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 * All Sound_Sample pointers you had prior to this call are INVALIDATED.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 * 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
204 * restart the subsystem. All default API states are restored at this
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 * point.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit()
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 * for you!
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 * @return nonzero on success, zero on error. Specifics of the error can be
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 * gleaned from Sound_GetLastError(). If failure, state of SDL_sound
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 * is undefined, and probably badly screwed up.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 extern DECLSPEC int Sound_Quit(void);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 * Get a list of sound formats supported by this implementation of SDL_sound.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 * This is for informational purposes only. Note that the extension listed is
11
Ryan C. Gordon <icculus@icculus.org>
parents: 3
diff changeset
220 * merely convention: if we list "MP3", you can open an MPEG-1 Layer 3 audio
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 * file with an extension of "XYZ", if you like. The file extensions are
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 * informational, and only required as a hint to choosing the correct
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 * decoder, since the sound data may not be coming from a file at all, thanks
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 * to the abstraction that an SDL_RWops provides.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 * The returned value is an array of pointers to Sound_DecoderInfo structures,
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 * with a NULL entry to signify the end of the list:
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 * Sound_DecoderInfo **i;
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 * for (i = Sound_AvailableDecoders(); *i != NULL; i++)
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 * {
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 * printf("Supported sound format: [%s], which is [%s].\n",
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 * i->extension, i->description);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 * // ...and other fields...
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 * }
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 * The return values are pointers to static internal memory, and should
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 * be considered READ ONLY, and never freed.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 * @return READ ONLY Null-terminated array of READ ONLY structures.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 extern DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 * Get the last SDL_sound error message as a null-terminated string.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 * This will be NULL if there's been no error since the last call to this
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 * function. The pointer returned by this call points to an internal buffer.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 * Each thread has a unique error state associated with it, but each time
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 * a new error message is set, it will overwrite the previous one associated
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 * with that thread. It is safe to call this function at anytime, even
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 * before Sound_Init().
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 * @return READ ONLY string of last error message.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 */
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
257 extern DECLSPEC const char *Sound_GetError(void);
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
258
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
259
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
260 /**
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
261 * 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
262 * return NULL.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
263 */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
264 extern DECLSPEC void Sound_ClearError(void);
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 * Start decoding a new sound sample. The data is read via an SDL_RWops
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 * structure (see SDL_rwops.h in the SDL include directory), so it may be
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 * coming from memory, disk, network stream, etc. The (ext) parameter is
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 * merely a hint to determining the correct decoder; if you specify, for
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 * 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
273 * 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
274 * 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
275 * 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
276 * 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
277 * need to be capable of rewinding to the start of the stream.
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 * If no decoders can handle the data, a NULL value is returned, and a human
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 * readable error message can be fetched from Sound_GetLastError().
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 * Optionally, a desired audio format can be specified. If the incoming data
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 * is in a different format, SDL_sound will convert it to the desired format
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 * on the fly. Note that this can be an expensive operation, so it may be
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 * wise to convert data before you need to play it back, if possible, or
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 * make sure your data is initially in the format that you need it in.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 * If you don't want to convert the data, you can specify NULL for a desired
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 * format. The incoming format of the data, preconversion, can be found
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 * in the Sound_Sample structure.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 * 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
289 * 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
290 * 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
291 * by the other decoders.
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 * Finally, specify an initial buffer size; this is the number of bytes that
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 * will be allocated to store each read from the sound buffer. The more you
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 * can safely allocate, the more decoding can be done in one block, but the
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 * more resources you have to use up, and the longer each decoding call will
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 * take. Note that different data formats require more or less space to
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 * 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
298 * 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
299 * 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
300 * 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
301 * 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
302 * 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
303 * in reality, you'll want to specify a MUCH larger buffer.
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 * When you are done with this Sound_Sample pointer, you can dispose of it
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 * via Sound_FreeSample().
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
306 * 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
307 * 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
308 * 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
309 * SDL_RWops for you.
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 * @param rw SDL_RWops with sound data.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 * @param ext File extension normally associated with a data format.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 * Can usually be NULL.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 * @param desired Format to convert sound data into. Can usually be NULL,
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 * if you don't need conversion.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 * @return Sound_Sample pointer, which is used as a handle to several other
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 * SDL_sound APIs. NULL on error. If error, use
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 * Sound_GetLastError() to see what went wrong.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 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
321 Sound_AudioInfo *desired,
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 Uint32 bufferSize);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 /**
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
325 * 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
326 * 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
327 * 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
328 * "/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
329 * 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
330 * (filename).
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
331 *
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
332 * @param filename file containing sound data.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
333 * @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
334 * if you don't need conversion.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
335 * @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
336 * @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
337 * 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
338 * Sound_GetLastError() to see what went wrong.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
339 */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
340 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
341 Sound_AudioInfo *desired,
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
342 Uint32 bufferSize);
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
343
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
344 /**
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 * Dispose of a Sound_Sample pointer that was returned from Sound_NewSample().
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 * This will also close/dispose of the SDL_RWops that was used at creation
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 * time, so there's no need to keep a reference to that around.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 * The Sound_Sample pointer is invalid after this call, and will almost
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 * certainly result in a crash if you attempt to keep using it.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 * @param sample The Sound_Sample to delete.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 extern DECLSPEC void Sound_FreeSample(Sound_Sample *sample);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 /**
3
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
357 * 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
358 * 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
359 * 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
360 * 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
361 * 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
362 * 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
363 * it yourself.
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
364 *
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
365 * 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
366 * 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
367 * 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
368 * 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
369 * 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
370 * 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
371 *
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
372 * @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
373 * @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
374 * @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
375 */
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
376 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
377
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
378
fd6cd0e04e6f First stab at implementation complete.
Ryan C. Gordon <icculus@icculus.org>
parents: 1
diff changeset
379 /**
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 * Decode more of the sound data in a Sound_Sample. It will decode at most
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 * sample->buffer_size bytes into sample->buffer in the desired format, and
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 * return the number of decoded bytes.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 * If sample->buffer_size bytes could not be decoded, then please refer to
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 * sample->flags to determine if this was an End-of-stream or error condition.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 * @param sample Do more decoding to this Sound_Sample.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 * @return number of bytes decoded into sample->buffer. If it is less than
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 * sample->buffer_size, then you should check sample->flags to see
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 * what the current state of the sample is (EOF, error, read again).
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 extern DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 /**
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 * Decode the remainder of the sound data in a Sound_Sample. This will
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 * dynamically allocate memory for the ENTIRE remaining sample.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 * sample->buffer_size and sample->buffer will be updated to reflect the
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 * new buffer. Please refer to sample->flags to determine if the decoding
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 * finished due to an End-of-stream or error condition.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 * Be aware that sound data can take a large amount of memory, and that
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 * this function may block for quite awhile while processing. Also note
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 * that a streaming source (for example, from a SDL_RWops that is getting
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 * fed from an Internet radio feed that doesn't end) may fill all available
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 * memory before giving up...be sure to use this on finite sound sources
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 * only!
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 *
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 * @param sample Do all decoding for this Sound_Sample.
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 * @return number of bytes decoded into sample->buffer. If it is less than
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 * sample->buffer_size, then you should check sample->flags to see
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 * what the current state of the sample is (EOF, error, read again).
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 extern DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample);
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 #ifdef __cplusplus
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 }
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 #endif
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418
1
508aac690b19 Whoops...changed some overlooked "voice" to "sound".
Ryan C. Gordon <icculus@icculus.org>
parents: 0
diff changeset
419 #endif /* !defined _INCLUDE_SDL_SOUND_H_ */
0
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 /* end of SDL_sound.h ... */
1078b3528e6f Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422