annotate SDL_sound_internal.h @ 143:3e60862fbd76

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