Mercurial > SDL_sound_CoreAudio
annotate decoders/skeleton.c @ 132:68d62a7fe33b
Upped version to 0.1.3.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 10 Oct 2001 00:43:39 +0000 |
parents | 40de367eb59e |
children | 1df5c106504e |
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 * | |
27 * Please see the file LICENSE in the source's root directory. | |
28 * | |
29 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
30 */ | |
31 | |
103
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
32 #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
|
33 #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
|
34 #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
|
35 #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
|
36 |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
37 #if HAVE_CONFIG_H |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
38 # include <config.h> |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
39 #endif |
100
6d9fdec2f708
added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents:
64
diff
changeset
|
40 |
103
706ec5842737
Updated for autoconf change, and placed #error messages so people don't
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
41 #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
|
42 |
16 | 43 #include <stdio.h> |
44 #include <stdlib.h> | |
45 #include <string.h> | |
46 #include <assert.h> | |
47 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
48 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
49 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
50 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
51 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
103
diff
changeset
|
52 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
53 static int FMT_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
54 static void FMT_quit(void); |
16 | 55 static int FMT_open(Sound_Sample *sample, const char *ext); |
56 static void FMT_close(Sound_Sample *sample); | |
57 static Uint32 FMT_read(Sound_Sample *sample); | |
58 | |
59 const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT = | |
60 { | |
61 { | |
62 "FMT", | |
63 "FMT audio format description", | |
64 "Ryan C. Gordon <icculus@clutteredmind.org>", | |
65 "http://www.icculus.org/SDL_sound/" | |
66 }, | |
67 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
68 FMT_init, /* init() method */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
69 FMT_quit, /* quit() method */ |
16 | 70 FMT_open, /* open() method */ |
71 FMT_close, /* close() method */ | |
72 FMT_read /* read() method */ | |
73 }; | |
74 | |
75 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
76 static int FMT_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
77 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
78 /* 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
|
79 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
80 return(1); /* initialization successful. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
81 } /* FMT_init */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
82 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
83 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
84 static void FMT_quit(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 cleanup you need here. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
87 } /* FMT_quit */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
88 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
89 |
16 | 90 static int FMT_open(Sound_Sample *sample, const char *ext) |
91 { | |
21
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
92 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
|
93 SDL_RWops *rw = internal->rw; |
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
94 |
16 | 95 if (can NOT accept the data) |
96 { | |
97 Sound_SetError("FMT: expected X, got Y."); | |
98 return(0); | |
99 } /* if */ | |
100 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
101 SNDDBG(("FMT: Accepting data stream.\n")); |
16 | 102 set up sample->actual; |
103 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
104 return(1); /* we'll handle this data. */ | |
105 } /* FMT_open */ | |
106 | |
107 | |
108 static void FMT_close(Sound_Sample *sample) | |
109 { | |
110 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
111 clean up anything you put into internal->decoder_private; | |
112 } /* FMT_close */ | |
113 | |
114 | |
115 static Uint32 FMT_read(Sound_Sample *sample) | |
116 { | |
117 Uint32 retval; | |
118 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
119 | |
120 /* | |
121 * We don't actually do any decoding, so we read the fmt data | |
122 * directly into the internal buffer... | |
123 */ | |
124 retval = SDL_RWread(internal->rw, internal->buffer, | |
125 1, internal->buffer_size); | |
126 | |
127 (or whatever. Do some decoding here...) | |
128 | |
129 /* Make sure the read went smoothly... */ | |
130 if (retval == 0) | |
131 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
132 | |
133 else if (retval == -1) | |
134 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
135 | |
136 /* (next call this EAGAIN may turn into an EOF or error.) */ | |
137 else if (retval < internal->buffer_size) | |
138 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; | |
139 | |
140 (or whatever. retval == number of bytes you put in internal->buffer). | |
141 | |
142 return(retval); | |
143 } /* FMT_read */ | |
144 | |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
145 #endif /* SOUND_SUPPORTS_FMT */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
146 |
16 | 147 |
148 /* end of fmt.c ... */ | |
149 |