Mercurial > SDL_sound_CoreAudio
annotate decoders/skeleton.c @ 49:365b3be64aac
Updated.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 22 Sep 2001 14:48:29 +0000 |
parents | ea58bc3b15d7 |
children | b13fafb976be |
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 | |
32 #include <stdio.h> | |
33 #include <stdlib.h> | |
34 #include <string.h> | |
35 #include <assert.h> | |
36 #include "SDL_sound.h" | |
37 | |
38 #define __SDL_SOUND_INTERNAL__ | |
39 #include "SDL_sound_internal.h" | |
40 | |
41 #if (!defined SOUND_SUPPORTS_FMT) | |
42 #error SOUND_SUPPORTS_FMT must be defined. | |
43 #endif | |
44 | |
45 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
46 static int FMT_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
47 static void FMT_quit(void); |
16 | 48 static int FMT_open(Sound_Sample *sample, const char *ext); |
49 static void FMT_close(Sound_Sample *sample); | |
50 static Uint32 FMT_read(Sound_Sample *sample); | |
51 | |
52 const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT = | |
53 { | |
54 { | |
55 "FMT", | |
56 "FMT audio format description", | |
57 "Ryan C. Gordon <icculus@clutteredmind.org>", | |
58 "http://www.icculus.org/SDL_sound/" | |
59 }, | |
60 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
61 FMT_init, /* init() method */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
62 FMT_quit, /* quit() method */ |
16 | 63 FMT_open, /* open() method */ |
64 FMT_close, /* close() method */ | |
65 FMT_read /* read() method */ | |
66 }; | |
67 | |
68 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
69 static int FMT_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
70 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
71 /* 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
|
72 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
73 return(1); /* initialization successful. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
74 } /* FMT_init */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
75 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
76 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
77 static void FMT_quit(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
78 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
79 /* 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
|
80 } /* FMT_quit */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
81 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
21
diff
changeset
|
82 |
16 | 83 static int FMT_open(Sound_Sample *sample, const char *ext) |
84 { | |
21
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
85 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
|
86 SDL_RWops *rw = internal->rw; |
d9b9d60cf9a9
Added some helpful info to FMT_open()...
Ryan C. Gordon <icculus@icculus.org>
parents:
16
diff
changeset
|
87 |
16 | 88 if (can NOT accept the data) |
89 { | |
90 Sound_SetError("FMT: expected X, got Y."); | |
91 return(0); | |
92 } /* if */ | |
93 | |
94 _D(("FMT: Accepting data stream.\n")); | |
95 set up sample->actual; | |
96 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
97 return(1); /* we'll handle this data. */ | |
98 } /* FMT_open */ | |
99 | |
100 | |
101 static void FMT_close(Sound_Sample *sample) | |
102 { | |
103 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
104 clean up anything you put into internal->decoder_private; | |
105 } /* FMT_close */ | |
106 | |
107 | |
108 static Uint32 FMT_read(Sound_Sample *sample) | |
109 { | |
110 Uint32 retval; | |
111 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
112 | |
113 /* | |
114 * We don't actually do any decoding, so we read the fmt data | |
115 * directly into the internal buffer... | |
116 */ | |
117 retval = SDL_RWread(internal->rw, internal->buffer, | |
118 1, internal->buffer_size); | |
119 | |
120 (or whatever. Do some decoding here...) | |
121 | |
122 /* Make sure the read went smoothly... */ | |
123 if (retval == 0) | |
124 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
125 | |
126 else if (retval == -1) | |
127 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
128 | |
129 /* (next call this EAGAIN may turn into an EOF or error.) */ | |
130 else if (retval < internal->buffer_size) | |
131 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; | |
132 | |
133 (or whatever. retval == number of bytes you put in internal->buffer). | |
134 | |
135 return(retval); | |
136 } /* FMT_read */ | |
137 | |
138 | |
139 /* end of fmt.c ... */ | |
140 |