Mercurial > SDL_sound_CoreAudio
annotate SDL_sound_internal.h @ 25:4acb5260d684
Made the SDL audio callback much more robust.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 19 Sep 2001 14:05:36 +0000 |
parents | 2888101dcf98 |
children | eeb874083218 |
rev | line source |
---|---|
4 | 1 /* |
2 * SDL_sound -- An abstract sound format decoding API. | |
3 * Copyright (C) 2001 Ryan C. Gordon. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 /* | |
21 * Internal function/structure declaration. Do NOT include in your | |
22 * application. | |
23 * | |
24 * Please see the file LICENSE in the source's root directory. | |
25 * | |
26 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
27 */ | |
28 | |
29 #ifndef _INCLUDE_SDL_SOUND_INTERNAL_H_ | |
30 #define _INCLUDE_SDL_SOUND_INTERNAL_H_ | |
31 | |
32 #ifndef __SDL_SOUND_INTERNAL__ | |
33 #error Do not include this header from your applications. | |
34 #endif | |
35 | |
36 #include "SDL.h" | |
37 | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
38 #if (defined DEBUG_CHATTER) |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
39 #define _D(x) printf x |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
40 #else |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
41 #define _D(x) |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
42 #endif |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
43 |
4 | 44 typedef struct __SOUND_DECODERFUNCTIONS__ |
45 { | |
46 /* This is a block of info about your decoder. See SDL_sound.h. */ | |
47 const Sound_DecoderInfo info; | |
48 | |
49 /* | |
50 * Returns non-zero if (sample) has a valid fileformat that this | |
51 * driver can handle. Zero if this driver can NOT handle the data. | |
52 * | |
53 * Extension, which may be NULL, is just a hint as to the form of | |
54 * data that is being passed in. Most decoders should determine if | |
55 * they can handle the data by the data itself, but others, like | |
56 * the raw data handler, need this hint to know if they should | |
57 * accept the data in the first place. | |
58 * | |
59 * (sample)'s (opaque) field should be cast to a Sound_SampleInternal | |
60 * pointer: | |
61 * | |
62 * Sound_SampleInternal *internal; | |
63 * internal = (Sound_SampleInternal *) sample->opaque; | |
64 * | |
65 * Certain fields of sample will be filled in for the decoder before | |
66 * this call, and others should be filled in by the decoder. Some | |
67 * fields are offlimits, and should NOT be modified. The list: | |
68 * | |
69 * in Sound_SampleInternal section: | |
70 * Sound_Sample *next; (offlimits) | |
71 * Sound_Sample *prev; (offlimits) | |
72 * SDL_RWops *rw; (can use, but do NOT close it) | |
73 * const Sound_DecoderFunctions *funcs; (that's this structure) | |
74 * SDL_AudioCVT sdlcvt; (offlimits) | |
75 * void *buffer; (offlimits until read() method) | |
76 * Uint32 buffer_size; (offlimits until read() method) | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
77 * void *decoder_private; (read and write access) |
4 | 78 * |
79 * in rest of Sound_Sample: | |
80 * void *opaque; (this was internal section, above) | |
81 * const Sound_DecoderInfo *decoder; (read only) | |
82 * Sound_AudioInfo desired; (read only, usually not needed here) | |
83 * Sound_AudioInfo actual; (please fill this in) | |
84 * void *buffer; (offlimits) | |
85 * Uint32 buffer_size; (offlimits) | |
86 * Sound_SampleFlags flags; (set appropriately) | |
87 */ | |
88 int (*open)(Sound_Sample *sample, const char *ext); | |
89 | |
90 /* | |
91 * Clean up. SDL_sound is done with this sample, so the decoder should | |
92 * clean up any resources it allocated. Anything that wasn't | |
93 * explicitly allocated by the decoder should be LEFT ALONE, since | |
94 * the higher-level SDL_sound layer will clean up its own mess. | |
95 */ | |
96 void (*close)(Sound_Sample *sample); | |
97 | |
98 /* | |
99 * Get more data from (sample). The decoder should get a pointer to | |
100 * the internal structure... | |
101 * | |
102 * Sound_SampleInternal *internal; | |
103 * internal = (Sound_SampleInternal *) sample->opaque; | |
104 * | |
105 * ...and then start decoding. Fill in up to internal->buffer_size | |
106 * bytes of decoded sound in the space pointed to by | |
107 * internal->buffer. The encoded data is read in from internal->rw. | |
108 * Data should be decoded in the format specified during the | |
109 * decoder's open() method in the sample->actual field. The | |
110 * conversion to the desired format is done at a higher level. | |
111 * | |
112 * The return value is the number of bytes decoded into | |
113 * internal->buffer, which can be no more than internal->buffer_size, | |
114 * but can be less. If it is less, you should set a state flag: | |
115 * | |
116 * If there's just no more data (end of file, etc), then do: | |
117 * sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
118 * | |
119 * If there's an unrecoverable error, then do: | |
120 * Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG); | |
121 * sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
122 * | |
123 * If there's more data, but you'd have to block for considerable | |
124 * amounts of time to get at it, or there's a recoverable error, | |
125 * then do: | |
126 * Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG); | |
127 * sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; | |
128 * | |
129 * SDL_sound will not call your read() method for any samples with | |
130 * SOUND_SAMPLEFLAG_EOF or SOUND_SAMPLEFLAG_ERROR set. The | |
131 * SOUND_SAMPLEFLAG_EAGAIN flag is reset before each call to this | |
132 * method. | |
133 */ | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
134 Uint32 (*read)(Sound_Sample *sample); |
4 | 135 } Sound_DecoderFunctions; |
136 | |
137 | |
138 typedef struct __SOUND_SAMPLEINTERNAL__ | |
139 { | |
140 Sound_Sample *next; | |
141 Sound_Sample *prev; | |
142 SDL_RWops *rw; | |
143 const Sound_DecoderFunctions *funcs; | |
144 SDL_AudioCVT sdlcvt; | |
145 void *buffer; | |
146 Uint32 buffer_size; | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
147 void *decoder_private; |
4 | 148 } Sound_SampleInternal; |
149 | |
150 | |
151 | |
152 /* error messages... */ | |
153 #define ERR_IS_INITIALIZED "Already initialized" | |
154 #define ERR_NOT_INITIALIZED "Not initialized" | |
155 #define ERR_INVALID_ARGUMENT "Invalid argument" | |
156 #define ERR_OUT_OF_MEMORY "Out of memory" | |
157 #define ERR_NOT_SUPPORTED "Operation not supported" | |
158 #define ERR_UNSUPPORTED_FORMAT "Sound format unsupported" | |
159 #define ERR_NOT_A_HANDLE "Not a file handle" | |
160 #define ERR_NO_SUCH_FILE "No such file" | |
161 #define ERR_PAST_EOF "Past end of file" | |
162 #define ERR_IO_ERROR "I/O error" | |
163 #define ERR_COMPRESSION "(De)compression error" | |
164 #define ERR_PREV_ERROR "Previous decoding already caused an error" | |
165 #define ERR_PREV_EOF "Previous decoding already triggered EOF" | |
166 | |
167 /* | |
168 * Call this to set the message returned by Sound_GetError(). | |
169 * Please only use the ERR_* constants above, or add new constants to the | |
170 * above group, but I want these all in one place. | |
171 * | |
172 * Calling this with a NULL argument is a safe no-op. | |
173 */ | |
174 void Sound_SetError(const char *err); | |
175 | |
176 | |
177 /* | |
178 * Use this if you need a cross-platform stricmp(). | |
179 */ | |
180 int __Sound_strcasecmp(const char *x, const char *y); | |
181 | |
182 | |
183 /* These get used all over for lessening code clutter. */ | |
184 #define BAIL_MACRO(e, r) { Sound_SetError(e); return r; } | |
185 #define BAIL_IF_MACRO(c, e, r) if (c) { Sound_SetError(e); return r; } | |
186 | |
187 | |
188 | |
189 | |
190 /*--------------------------------------------------------------------------*/ | |
191 /*--------------------------------------------------------------------------*/ | |
192 /*------------ ----------------*/ | |
193 /*------------ You MUST implement the following functions ----------------*/ | |
194 /*------------ if porting to a new platform. ----------------*/ | |
195 /*------------ (see platform/unix.c for an example) ----------------*/ | |
196 /*------------ ----------------*/ | |
197 /*--------------------------------------------------------------------------*/ | |
198 /*--------------------------------------------------------------------------*/ | |
199 | |
200 | |
201 /* (None, right now.) */ | |
202 | |
203 | |
204 #ifdef __cplusplus | |
205 extern "C" { | |
206 #endif | |
207 | |
208 #endif /* defined _INCLUDE_SDL_SOUND_INTERNAL_H_ */ | |
209 | |
210 /* end of SDL_sound_internal.h ... */ | |
211 |