Mercurial > SDL_sound_CoreAudio
annotate decoders/raw.c @ 221:c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 17 Jan 2002 20:53:53 +0000 |
parents | 47cc2de2ae36 |
children | c97be6e1bd27 |
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 * RAW decoder for SDL_sound. This is as simple as it gets. | |
22 * | |
23 * This driver handles raw audio data. You must, regardless of where the | |
24 * data is actually coming from, specify the string "RAW" in the extension | |
25 * parameter of Sound_NewSample() (or, alternately, open a file with the | |
26 * extension ".raw" in Sound_NewSampleFromFile()). The string is checked | |
27 * case-insensitive. We need this check, because raw data, being raw, has | |
28 * no headers or magic number we can use to determine if we should handle a | |
29 * given file, so we needed some way to have this "decoder" discriminate. | |
30 * | |
31 * When calling Sound_NewSample*(), you must also specify a "desired" | |
32 * audio format. The "actual" format will always match what you specify, so | |
33 * there will be no conversion overhead, but these routines need to know how | |
34 * to treat the bits, since it's all random garbage otherwise. | |
35 * | |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
36 * Please see the file COPYING in the source's root directory. |
4 | 37 * |
38 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) | |
39 */ | |
40 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
41 #if HAVE_CONFIG_H |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
42 # include <config.h> |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
43 #endif |
100
6d9fdec2f708
added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents:
64
diff
changeset
|
44 |
104
103cfcb3c014
Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
45 #ifdef SOUND_SUPPORTS_RAW |
103cfcb3c014
Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
46 |
4 | 47 #include <stdio.h> |
48 #include <stdlib.h> | |
49 #include <string.h> | |
50 #include <assert.h> | |
51 | |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
52 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
53 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
54 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
55 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
56 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
57 static int RAW_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
58 static void RAW_quit(void); |
4 | 59 static int RAW_open(Sound_Sample *sample, const char *ext); |
60 static void RAW_close(Sound_Sample *sample); | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
61 static Uint32 RAW_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
|
62 static int RAW_rewind(Sound_Sample *sample); |
4 | 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_raw[] = { "RAW", NULL }; |
4 | 65 const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW = |
66 { | |
67 { | |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
106
diff
changeset
|
68 extensions_raw, |
4 | 69 "Raw audio", |
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 RAW_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
75 RAW_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
76 RAW_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
77 RAW_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
78 RAW_read, /* read() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
79 RAW_rewind /* rewind() method */ |
4 | 80 }; |
81 | |
82 | |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
83 static int RAW_init(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
84 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
85 return(1); /* always succeeds. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
86 } /* RAW_init */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
87 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
88 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
89 static void RAW_quit(void) |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
90 { |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
91 /* it's a no-op. */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
92 } /* RAW_quit */ |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
93 |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
7
diff
changeset
|
94 |
4 | 95 static int RAW_open(Sound_Sample *sample, const char *ext) |
96 { | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
97 /* |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
98 * We check this explicitly, since we have no other way to |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
99 * determine whether we should handle this data or not. |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
100 */ |
4 | 101 if (__Sound_strcasecmp(ext, "RAW") != 0) |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
102 { |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
103 Sound_SetError("RAW: extension isn't explicitly \"RAW\"."); |
4 | 104 return(0); |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
105 } /* if */ |
4 | 106 |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
107 /* |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
108 * You must also specify a desired format, so we know how to |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
109 * treat the bits that are otherwise binary garbage. |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
110 */ |
4 | 111 if ( (sample->desired.channels < 1) || |
112 (sample->desired.channels > 2) || | |
113 (sample->desired.rate == 0) || | |
114 (sample->desired.format == 0) ) | |
115 { | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
116 Sound_SetError("RAW: invalid desired format."); |
4 | 117 return(0); |
118 } /* if */ | |
119 | |
62
b13fafb976be
Changed _D macro to DBGSND.
Ryan C. Gordon <icculus@icculus.org>
parents:
47
diff
changeset
|
120 SNDDBG(("RAW: Accepting data stream.\n")); |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
121 |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
122 /* |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
123 * We never convert raw samples; what you ask for is what you get. |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
124 */ |
4 | 125 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); |
126 sample->flags = SOUND_SAMPLEFLAG_NONE; | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
127 |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
128 return(1); /* we'll handle this data. */ |
4 | 129 } /* RAW_open */ |
130 | |
131 | |
132 static void RAW_close(Sound_Sample *sample) | |
133 { | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
134 /* we don't allocate anything that we need to free. That's easy, eh? */ |
4 | 135 } /* RAW_close */ |
136 | |
137 | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
138 static Uint32 RAW_read(Sound_Sample *sample) |
4 | 139 { |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
140 Uint32 retval; |
4 | 141 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
142 |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
143 /* |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
144 * We don't actually do any decoding, so we read the raw data |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
145 * directly into the internal buffer... |
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
146 */ |
4 | 147 retval = SDL_RWread(internal->rw, internal->buffer, |
148 1, internal->buffer_size); | |
149 | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
150 /* Make sure the read went smoothly... */ |
4 | 151 if (retval == 0) |
152 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
153 | |
154 else if (retval == -1) | |
155 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | |
156 | |
7
29313c20963d
Updated a lot of comments, and changed read() method's return type.
Ryan C. Gordon <icculus@icculus.org>
parents:
4
diff
changeset
|
157 /* (next call this EAGAIN may turn into an EOF or error.) */ |
4 | 158 else if (retval < internal->buffer_size) |
159 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; | |
160 | |
161 return(retval); | |
162 } /* RAW_read */ | |
163 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
164 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
165 static int RAW_rewind(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
166 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
167 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
|
168 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
|
169 return(1); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
170 } /* RAW_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
171 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
172 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
173 #endif /* SOUND_SUPPORTS_RAW */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
174 |
4 | 175 |
176 /* end of raw.c ... */ | |
177 |