Mercurial > SDL_sound_CoreAudio
annotate decoders/skeleton.c @ 359:2b7969823778
Updated.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 11 Jun 2002 23:33:27 +0000 |
parents | c97be6e1bd27 |
children | cbb15ecf423a |
rev | line source |
---|---|
16 | 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 * FMT decoder for SDL_sound. | |
22 * | |
23 * This driver handles FMT audio data. Blahblahblah... The author should | |
24 * have done a search and replace on "fmt" and "FMT" and changed this | |
25 * comment. This is the default comment in the skeleton decoder file... | |
26 * | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
27 * None of this code, even the parts that LOOK right, have been compiled, |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
28 * so you cut-and-paste at your own risk. |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
29 * |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
30 * Please see the file COPYING in the source's root directory. |
16 | 31 * |
32 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
33 */ | |
34 | |
103
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
35 #error DO NOT COMPILE THIS. |
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
36 #error This is an example decoder skeleton. |
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
37 #error You should base your code on this file, and remove these error lines |
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
38 #error from your version. |
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
39 |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
40 #if HAVE_CONFIG_H |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
41 # include <config.h> |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
42 #endif |
100
6d9fdec2f708
added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents:
64
diff
changeset
|
43 |
103
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
44 #ifdef SOUND_SUPPORTS_FMT |
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
45 |
16 | 46 #include <stdio.h> |
47 #include <stdlib.h> | |
48 #include <string.h> | |
49 #include <assert.h> | |
50 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
51 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
52 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
53 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
54 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
55 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
56 static int FMT_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
57 static void FMT_quit(void); |
16 | 58 static int FMT_open(Sound_Sample *sample, const char *ext); |
59 static void FMT_close(Sound_Sample *sample); | |
60 static Uint32 FMT_read(Sound_Sample *sample); | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
61 static int FMT_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
62 static int FMT_seek(Sound_Sample *sample, Uint32 ms); |
16 | 63 |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
106
diff
changeset
|
64 static const char *extensions_fmt[] = { "FMT", NULL }; |
16 | 65 const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT = |
66 { | |
67 { | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
106
diff
changeset
|
68 extensions_fmt, |
16 | 69 "FMT audio format description", |
70 "Ryan C. Gordon <icculus@clutteredmind.org>", | |
71 "http://www.icculus.org/SDL_sound/" | |
72 }, | |
73 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
74 FMT_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
75 FMT_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
76 FMT_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
77 FMT_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
78 FMT_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
79 FMT_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
80 FMT_seek /* seek() method */ |
16 | 81 }; |
82 | |
83 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
84 static int FMT_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
85 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
86 /* do any global decoder/library initialization you need here. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
87 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
88 return(1); /* initialization successful. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
89 } /* FMT_init */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
90 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
91 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
92 static void FMT_quit(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
93 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
94 /* do any global decoder/library cleanup you need here. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
95 } /* FMT_quit */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
96 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
97 |
16 | 98 static int FMT_open(Sound_Sample *sample, const char *ext) |
99 { | |
21
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
100 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
101 SDL_RWops *rw = internal->rw; |
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
102 |
16 | 103 if (can NOT accept the data) |
104 { | |
105 Sound_SetError("FMT: expected X, got Y."); | |
106 return(0); | |
107 } /* if */ | |
108 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
109 SNDDBG(("FMT: Accepting data stream.\n")); |
16 | 110 set up sample->actual; |
111 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
112 return(1); /* we'll handle this data. */ | |
113 } /* FMT_open */ | |
114 | |
115 | |
116 static void FMT_close(Sound_Sample *sample) | |
117 { | |
118 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
119 clean up anything you put into internal->decoder_private; | |
120 } /* FMT_close */ | |
121 | |
122 | |
123 static Uint32 FMT_read(Sound_Sample *sample) | |
124 { | |
125 Uint32 retval; | |
126 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
127 | |
128 /* | |
129 * We don't actually do any decoding, so we read the fmt data | |
130 * directly into the internal buffer... | |
131 */ | |
132 retval = SDL_RWread(internal->rw, internal->buffer, | |
133 1, internal->buffer_size); | |
134 | |
135 (or whatever. Do some decoding here...) | |
136 | |
137 /* Make sure the read went smoothly... */ | |
138 if (retval == 0) | |
139 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
140 | |
141 else if (retval == -1) | |
142 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
143 | |
144 /* (next call this EAGAIN may turn into an EOF or error.) */ | |
145 else if (retval < internal->buffer_size) | |
146 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; | |
147 | |
148 (or whatever. retval == number of bytes you put in internal->buffer). | |
149 | |
150 return(retval); | |
151 } /* FMT_read */ | |
152 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
153 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
154 static int FMT_rewind(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
155 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
156 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
157 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
158 /* seek to the appropriate place... */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
159 BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
160 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
161 (reset state as necessary.) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
162 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
163 return(1); /* success. */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
164 } /* FMT_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
165 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
166 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
167 static int FMT_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
168 { |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
169 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
170 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
171 /* seek to the appropriate place... */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
172 BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0); |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
173 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
174 (set state as necessary.) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
175 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
176 return(1); /* success. */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
177 } /* FMT_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
178 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
179 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
180 #endif /* SOUND_SUPPORTS_FMT */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
181 |
16 | 182 |
183 /* end of fmt.c ... */ | |
184 |