Mercurial > SDL_sound_CoreAudio
annotate SDL_sound_internal.h @ 578:7ff36153215a
Fixed 48-byte memory leak.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 06 Nov 2010 00:27:45 -0700 |
parents | 2e8907ff98e9 |
children |
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 * | |
552
2e8907ff98e9
Replaced references to COPYING with references to LICENSE.txt ...
Ryan C. Gordon <icculus@icculus.org>
parents:
526
diff
changeset
|
24 * Please see the file LICENSE.txt in the source's root directory. |
4 | 25 * |
526
2df1f5c62d38
Updated my email address.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
26 * This file written by Ryan C. Gordon. (icculus@icculus.org) |
4 | 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 | |
401
c42ac9ee2ce4
Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
387
diff
changeset
|
38 /* SDL 1.2.4 defines this, but better safe than sorry. */ |
c42ac9ee2ce4
Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
387
diff
changeset
|
39 #if (!defined(__inline__)) |
c42ac9ee2ce4
Fixed "inline" keyword to compile.
Ryan C. Gordon <icculus@icculus.org>
parents:
387
diff
changeset
|
40 # define __inline__ |
301 | 41 #endif |
42 | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
43 #if (defined DEBUG_CHATTER) |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
42
diff
changeset
|
44 #define SNDDBG(x) printf x |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
45 #else |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
42
diff
changeset
|
46 #define SNDDBG(x) |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
47 #endif |
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
48 |
377
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
49 #if HAVE_ASSERT_H |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
50 # include <assert.h> |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
51 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
52 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
53 #ifdef _WIN32_WCE |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
54 extern char *strrchr(const char *s, int c); |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
55 # ifdef NDEBUG |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
56 # define assert(x) |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
57 # else |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
58 # define assert(x) if(!x) { fprintf(stderr,"Assertion failed in %s, line %s.\n",__FILE__,__LINE__); fclose(stderr); fclose(stdout); exit(1); } |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
59 # endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
60 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
61 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
62 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
63 #if (!defined assert) /* if all else fails. */ |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
64 # define assert(x) |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
65 #endif |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
66 |
cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
Ryan C. Gordon <icculus@icculus.org>
parents:
340
diff
changeset
|
67 |
485
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
68 /* |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
69 * SDL itself only supports mono and stereo output, but hopefully we can |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
70 * raise this value someday...there's probably a lot of assumptions in |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
71 * SDL_sound that rely on it, though. |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
72 */ |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
73 #define MAX_CHANNELS 2 |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
74 |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
75 |
4 | 76 typedef struct __SOUND_DECODERFUNCTIONS__ |
77 { | |
78 /* This is a block of info about your decoder. See SDL_sound.h. */ | |
79 const Sound_DecoderInfo info; | |
80 | |
81 /* | |
42
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
82 * This is called during the Sound_Init() function. Use this to |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
83 * set up any global state that your decoder needs, such as |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
84 * initializing an external library, etc. |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
85 * |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
86 * Return non-zero if initialization is successful, zero if there's |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
87 * a fatal error. If this method fails, then this decoder is |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
88 * flagged as unavailable until SDL_sound() is shut down and |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
89 * reinitialized, in which case this method will be tried again. |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
90 * |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
91 * Note that the decoders quit() method won't be called if this |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
92 * method fails, so if you can't intialize, you'll have to clean |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
93 * up the half-initialized state in this method. |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
94 */ |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
95 int (*init)(void); |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
96 |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
97 /* |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
98 * This is called during the Sound_Quit() function. Use this to |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
99 * clean up any global state that your decoder has used during its |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
100 * lifespan. |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
101 */ |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
102 void (*quit)(void); |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
103 |
2b63642fb6ff
Removed MULTIPLE_STREAMS_PER_RWOPS and added init() and quit() methods to
Ryan C. Gordon <icculus@icculus.org>
parents:
39
diff
changeset
|
104 /* |
4 | 105 * Returns non-zero if (sample) has a valid fileformat that this |
106 * driver can handle. Zero if this driver can NOT handle the data. | |
107 * | |
108 * Extension, which may be NULL, is just a hint as to the form of | |
109 * data that is being passed in. Most decoders should determine if | |
110 * they can handle the data by the data itself, but others, like | |
111 * the raw data handler, need this hint to know if they should | |
112 * accept the data in the first place. | |
113 * | |
114 * (sample)'s (opaque) field should be cast to a Sound_SampleInternal | |
115 * pointer: | |
116 * | |
117 * Sound_SampleInternal *internal; | |
118 * internal = (Sound_SampleInternal *) sample->opaque; | |
119 * | |
120 * Certain fields of sample will be filled in for the decoder before | |
121 * this call, and others should be filled in by the decoder. Some | |
122 * fields are offlimits, and should NOT be modified. The list: | |
123 * | |
124 * in Sound_SampleInternal section: | |
125 * Sound_Sample *next; (offlimits) | |
126 * Sound_Sample *prev; (offlimits) | |
127 * SDL_RWops *rw; (can use, but do NOT close it) | |
128 * const Sound_DecoderFunctions *funcs; (that's this structure) | |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
129 * Sound_AudioCVT sdlcvt; (offlimits) |
4 | 130 * void *buffer; (offlimits until read() method) |
131 * 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
|
132 * void *decoder_private; (read and write access) |
4 | 133 * |
134 * in rest of Sound_Sample: | |
135 * void *opaque; (this was internal section, above) | |
136 * const Sound_DecoderInfo *decoder; (read only) | |
137 * Sound_AudioInfo desired; (read only, usually not needed here) | |
138 * Sound_AudioInfo actual; (please fill this in) | |
139 * void *buffer; (offlimits) | |
140 * Uint32 buffer_size; (offlimits) | |
141 * Sound_SampleFlags flags; (set appropriately) | |
142 */ | |
143 int (*open)(Sound_Sample *sample, const char *ext); | |
144 | |
145 /* | |
146 * Clean up. SDL_sound is done with this sample, so the decoder should | |
147 * clean up any resources it allocated. Anything that wasn't | |
148 * explicitly allocated by the decoder should be LEFT ALONE, since | |
149 * the higher-level SDL_sound layer will clean up its own mess. | |
150 */ | |
151 void (*close)(Sound_Sample *sample); | |
152 | |
153 /* | |
154 * Get more data from (sample). The decoder should get a pointer to | |
155 * the internal structure... | |
156 * | |
157 * Sound_SampleInternal *internal; | |
158 * internal = (Sound_SampleInternal *) sample->opaque; | |
159 * | |
160 * ...and then start decoding. Fill in up to internal->buffer_size | |
161 * bytes of decoded sound in the space pointed to by | |
162 * internal->buffer. The encoded data is read in from internal->rw. | |
163 * Data should be decoded in the format specified during the | |
164 * decoder's open() method in the sample->actual field. The | |
165 * conversion to the desired format is done at a higher level. | |
166 * | |
167 * The return value is the number of bytes decoded into | |
168 * internal->buffer, which can be no more than internal->buffer_size, | |
169 * but can be less. If it is less, you should set a state flag: | |
170 * | |
171 * If there's just no more data (end of file, etc), then do: | |
172 * sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
173 * | |
174 * If there's an unrecoverable error, then do: | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
175 * __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG); |
4 | 176 * sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
177 * | |
178 * If there's more data, but you'd have to block for considerable | |
179 * amounts of time to get at it, or there's a recoverable error, | |
180 * then do: | |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
181 * __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG); |
4 | 182 * sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
183 * | |
184 * SDL_sound will not call your read() method for any samples with | |
185 * SOUND_SAMPLEFLAG_EOF or SOUND_SAMPLEFLAG_ERROR set. The | |
186 * SOUND_SAMPLEFLAG_EAGAIN flag is reset before each call to this | |
187 * method. | |
188 */ | |
12
2888101dcf98
Added _D(()) macro, decoder_private field, and changed read() method from
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
189 Uint32 (*read)(Sound_Sample *sample); |
223
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
190 |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
191 /* |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
192 * Reset the decoding to the beginning of the stream. Nonzero on |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
193 * success, zero on failure. |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
194 * |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
195 * The purpose of this method is to allow for higher efficiency than |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
196 * an application could get by just recreating the sample externally; |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
197 * not only do they not have to reopen the RWops, reallocate buffers, |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
198 * and potentially pass the data through several rejecting decoders, |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
199 * but certain decoders will not have to recreate their existing |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
200 * state (search for metadata, etc) since they already know they |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
201 * have a valid audio stream with a given set of characteristics. |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
202 * |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
203 * The decoder is responsible for calling seek() on the associated |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
204 * SDL_RWops. A failing call to seek() should be the ONLY reason that |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
205 * this method should ever fail! |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
206 */ |
249186e31431
Sound_Rewind() support code.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
207 int (*rewind)(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
208 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
209 /* |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
210 * Reposition the decoding to an arbitrary point. Nonzero on |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
211 * success, zero on failure. |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
212 * |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
213 * The purpose of this method is to allow for higher efficiency than |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
214 * an application could get by just rewinding the sample and |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
215 * decoding to a given point. |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
216 * |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
217 * The decoder is responsible for calling seek() on the associated |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
218 * SDL_RWops. |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
219 * |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
220 * If there is an error, try to recover so that the next read will |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
221 * continue as if nothing happened. |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
222 */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
223 int (*seek)(Sound_Sample *sample, Uint32 ms); |
4 | 224 } Sound_DecoderFunctions; |
225 | |
226 | |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
227 /* A structure to hold a set of audio conversion filters and buffers */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
228 typedef struct Sound_AudioCVT |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
229 { |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
230 int needed; /* Set to 1 if conversion possible */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
231 Uint16 src_format; /* Source audio format */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
232 Uint16 dst_format; /* Target audio format */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
233 double rate_incr; /* Rate conversion increment */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
234 Uint8 *buf; /* Buffer to hold entire audio data */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
235 int len; /* Length of original audio buffer */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
236 int len_cvt; /* Length of converted audio buffer */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
237 int len_mult; /* buffer must be len*len_mult big */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
238 double len_ratio; /* Given len, final size is len*len_ratio */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
239 void (*filters[20])(struct Sound_AudioCVT *cvt, Uint16 *format); |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
240 int filter_index; /* Current audio conversion function */ |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
241 } Sound_AudioCVT; |
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
242 |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
243 extern SNDDECLSPEC int Sound_BuildAudioCVT(Sound_AudioCVT *cvt, |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
244 Uint16 src_format, Uint8 src_channels, Uint32 src_rate, |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
245 Uint16 dst_format, Uint8 dst_channels, Uint32 dst_rate, |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
246 Uint32 dst_size); |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
247 |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
248 extern SNDDECLSPEC int Sound_ConvertAudio(Sound_AudioCVT *cvt); |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
249 |
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
250 |
485
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
251 typedef void (*MixFunc)(float *dst, void *src, Uint32 frames, float *gains); |
441
5b00e43ec23c
Patches to make SDL_sound more Visual C happy.
Ryan C. Gordon <icculus@icculus.org>
parents:
401
diff
changeset
|
252 |
4 | 253 typedef struct __SOUND_SAMPLEINTERNAL__ |
254 { | |
255 Sound_Sample *next; | |
256 Sound_Sample *prev; | |
257 SDL_RWops *rw; | |
258 const Sound_DecoderFunctions *funcs; | |
143
3e60862fbd76
Start of audio converter work.
Ryan C. Gordon <icculus@icculus.org>
parents:
107
diff
changeset
|
259 Sound_AudioCVT sdlcvt; |
4 | 260 void *buffer; |
261 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
|
262 void *decoder_private; |
477
3e705c9180e5
Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents:
441
diff
changeset
|
263 Sint32 total_time; |
485
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
264 Uint32 mix_position; |
137c0b00ea4c
Added Sound_NewSampleFromMem(), and implementation of RWops pooling.
Ryan C. Gordon <icculus@icculus.org>
parents:
483
diff
changeset
|
265 MixFunc mix; |
4 | 266 } Sound_SampleInternal; |
267 | |
268 | |
269 /* error messages... */ | |
270 #define ERR_IS_INITIALIZED "Already initialized" | |
271 #define ERR_NOT_INITIALIZED "Not initialized" | |
272 #define ERR_INVALID_ARGUMENT "Invalid argument" | |
273 #define ERR_OUT_OF_MEMORY "Out of memory" | |
274 #define ERR_NOT_SUPPORTED "Operation not supported" | |
275 #define ERR_UNSUPPORTED_FORMAT "Sound format unsupported" | |
276 #define ERR_NOT_A_HANDLE "Not a file handle" | |
277 #define ERR_NO_SUCH_FILE "No such file" | |
278 #define ERR_PAST_EOF "Past end of file" | |
279 #define ERR_IO_ERROR "I/O error" | |
280 #define ERR_COMPRESSION "(De)compression error" | |
281 #define ERR_PREV_ERROR "Previous decoding already caused an error" | |
282 #define ERR_PREV_EOF "Previous decoding already triggered EOF" | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
283 #define ERR_CANNOT_SEEK "Sample is not seekable" |
4 | 284 |
285 /* | |
286 * Call this to set the message returned by Sound_GetError(). | |
287 * Please only use the ERR_* constants above, or add new constants to the | |
288 * above group, but I want these all in one place. | |
289 * | |
290 * Calling this with a NULL argument is a safe no-op. | |
291 */ | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
292 void __Sound_SetError(const char *err); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
293 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
294 /* |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
295 * Call this to convert milliseconds to an actual byte position, based on |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
296 * audio data characteristics. |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
297 */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
298 Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms); |
4 | 299 |
300 /* | |
301 * Use this if you need a cross-platform stricmp(). | |
302 */ | |
303 int __Sound_strcasecmp(const char *x, const char *y); | |
304 | |
305 | |
306 /* These get used all over for lessening code clutter. */ | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
307 #define BAIL_MACRO(e, r) { __Sound_SetError(e); return r; } |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
301
diff
changeset
|
308 #define BAIL_IF_MACRO(c, e, r) if (c) { __Sound_SetError(e); return r; } |
4 | 309 |
310 | |
311 | |
312 | |
313 /*--------------------------------------------------------------------------*/ | |
314 /*--------------------------------------------------------------------------*/ | |
315 /*------------ ----------------*/ | |
316 /*------------ You MUST implement the following functions ----------------*/ | |
317 /*------------ if porting to a new platform. ----------------*/ | |
318 /*------------ (see platform/unix.c for an example) ----------------*/ | |
319 /*------------ ----------------*/ | |
320 /*--------------------------------------------------------------------------*/ | |
321 /*--------------------------------------------------------------------------*/ | |
322 | |
323 | |
324 /* (None, right now.) */ | |
325 | |
326 | |
327 #ifdef __cplusplus | |
328 extern "C" { | |
329 #endif | |
330 | |
331 #endif /* defined _INCLUDE_SDL_SOUND_INTERNAL_H_ */ | |
332 | |
333 /* end of SDL_sound_internal.h ... */ | |
334 |