Mercurial > SDL_sound_CoreAudio
annotate decoders/aiff.c @ 250:649a7592e1c9
Updated.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 07 Feb 2002 08:11:00 +0000 |
parents | c9772a9f5271 |
children | c97be6e1bd27 |
rev | line source |
---|---|
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 * SDL_sound -- An abstract sound format decoding API. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 * Copyright (C) 2001 Ryan C. Gordon. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 * AIFF decoder for SDL_sound |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 * [Insert something profound about the AIFF file format here.] |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 * This code was ripped from a decoder I had written for SDL_mixer, which was |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 * based on SDL_mixer's old AIFF music loader. (This loader was unfortunately |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 * completely broken, but it was still useful because all the pieces were |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 * still there, so to speak.) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 * When rewriting it for SDL_sound, I changed its structure to be more like |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 * the WAV loader Ryan wrote. Had they not both been part of the same project |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 * it would have been embarrassing how similar they are. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 * It is not the most feature-complete AIFF loader the world has ever seen. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 * For instance, it only makes a token attempt at implementing the AIFF-C |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 * standard; basically the parts of it that I can easily understand and test. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 * It's a start, though. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 * |
184
47cc2de2ae36
Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents:
180
diff
changeset
|
39 * Please see the file COPYING in the source's root directory. |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 * This file was written by Torbjörn Andersson. (d91tan@Update.UU.SE) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
44 #if HAVE_CONFIG_H |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
45 # include <config.h> |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
46 #endif |
100
6d9fdec2f708
added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents:
64
diff
changeset
|
47 |
104
103cfcb3c014
Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
48 #ifdef SOUND_SUPPORTS_AIFF |
103cfcb3c014
Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
49 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 #include <stdio.h> |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 #include <stdlib.h> |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 #include <string.h> |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 #include <assert.h> |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
55 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
56 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
57 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
58 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
59 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
60 static Uint32 SANE_to_Uint32 (Uint8 *sanebuf); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
61 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
62 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
63 static int AIFF_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
64 static void AIFF_quit(void); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 static int AIFF_open(Sound_Sample *sample, const char *ext); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 static void AIFF_close(Sound_Sample *sample); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 static Uint32 AIFF_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
|
68 static int AIFF_rewind(Sound_Sample *sample); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
116
diff
changeset
|
70 static const char *extensions_aiff[] = { "AIFF", NULL }; |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF = |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 { |
149
1df5c106504e
Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents:
116
diff
changeset
|
74 extensions_aiff, |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 "Audio Interchange File Format", |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 "Torbjörn Andersson <d91tan@Update.UU.SE>", |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 "http://www.icculus.org/SDL_sound/" |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 }, |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
80 AIFF_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
81 AIFF_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
82 AIFF_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
83 AIFF_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
84 AIFF_read, /* read() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
85 AIFF_rewind /* rewind() method */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 }; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
89 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
90 * aiff_t is what we store in our internal->decoder_private field... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
91 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
92 typedef struct S_AIFF_FMT_T |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
93 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
94 Uint32 type; |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
95 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
96 Uint32 total_bytes; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
97 Uint32 data_starting_offset; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
98 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
99 void (*free)(struct S_AIFF_FMT_T *fmt); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
100 Uint32 (*read_sample)(Sound_Sample *sample); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
101 int (*rewind_sample)(Sound_Sample *sample); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
102 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
103 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
104 #if 0 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
105 /* |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
106 this is ripped from wav.c as ann example of format-specific data. |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
107 please replace with something more appropriate when the need arises. |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
108 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
109 union |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
110 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
111 struct |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
112 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
113 Uint16 cbSize; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
114 Uint16 wSamplesPerBlock; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
115 Uint16 wNumCoef; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
116 ADPCMCOEFSET *aCoeff; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
117 } adpcm; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
118 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
119 /* put other format-specific data here... */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
120 } fmt; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
121 #endif |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
122 } fmt_t; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
123 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
124 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
125 typedef struct |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
126 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
127 fmt_t fmt; |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 Sint32 bytesLeft; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 } aiff_t; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
132 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 /* Chunk management code... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
135 #define formID 0x4D524F46 /* "FORM", in ascii. */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 #define aiffID 0x46464941 /* "AIFF", in ascii. */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 #define aifcID 0x43464941 /* "AIFC", in ascii. */ |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
138 #define ssndID 0x444E5353 /* "SSND", in ascii. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
139 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
141 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
142 * The COMM chunk... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
143 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
144 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
145 #define commID 0x4D4D4F43 /* "COMM", in ascii. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
146 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
147 /* format/compression types... */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
148 #define noneID 0x454E4F4E /* "NONE", in ascii. */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 typedef struct |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 Uint32 ckID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 Uint32 ckDataSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 Uint16 numChannels; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 Uint32 numSampleFrames; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 Uint16 sampleSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 Uint32 sampleRate; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 * We don't handle AIFF-C compressed audio yet, but for those |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 * interested the allowed compression types are supposed to be |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 * compressionType compressionName meaning |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 * --------------------------------------------------------------- |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 * 'NONE' "not compressed" uncompressed, that is, |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 * straight digitized samples |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 * 'ACE2' "ACE 2-to-1" 2-to-1 IIGS ACE (Audio |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 * Compression / Expansion) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 * 'ACE8' "ACE 8-to-3" 8-to-3 IIGS ACE (Audio |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 * Compression / Expansion) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 * 'MAC3' "MACE 3-to-1" 3-to-1 Macintosh Audio |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 * Compression / Expansion |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 * 'MAC6' "MACE 6-to-1" 6-to-1 Macintosh Audio |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 * Compression / Expansion |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 * A pstring is a "Pascal-style string", that is, "one byte followed |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 * by test bytes followed when needed by one pad byte. The total |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 * number of bytes in a pstring must be even. The pad byte is |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 * included when the number of text bytes is even, so the total of |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 * text bytes + one count byte + one pad byte will be even. This pad |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 * byte is not reflected in the count." |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 * As for how these compression algorithms work, your guess is as |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 * good as mine. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 Uint32 compressionType; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 #if 0 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 pstring compressionName; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 #endif |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 } comm_t; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 * Read in a comm_t from disk. This makes this process safe regardless of |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 * the processor's byte order or how the comm_t structure is packed. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 static int read_comm_chunk(SDL_RWops *rw, comm_t *comm) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 Uint8 sampleRate[10]; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 /* skip reading the chunk ID, since it was already read at this point... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 comm->ckID = commID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 if (SDL_RWread(rw, &comm->ckDataSize, sizeof (comm->ckDataSize), 1) != 1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 comm->ckDataSize = SDL_SwapBE32(comm->ckDataSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 if (SDL_RWread(rw, &comm->numChannels, sizeof (comm->numChannels), 1) != 1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 comm->numChannels = SDL_SwapBE16(comm->numChannels); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
212 if (SDL_RWread(rw, &comm->numSampleFrames, |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
213 sizeof (comm->numSampleFrames), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 if (SDL_RWread(rw, &comm->sampleSize, sizeof (comm->sampleSize), 1) != 1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 comm->sampleSize = SDL_SwapBE16(comm->sampleSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
221 if (SDL_RWread(rw, sampleRate, sizeof (sampleRate), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 comm->sampleRate = SANE_to_Uint32(sampleRate); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 if (comm->ckDataSize > sizeof(comm->numChannels) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 + sizeof(comm->numSampleFrames) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 + sizeof(comm->sampleSize) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 + sizeof(sampleRate)) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 { |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
230 if (SDL_RWread(rw, &comm->compressionType, |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
231 sizeof (comm->compressionType), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 comm->compressionType = SDL_SwapBE32(comm->compressionType); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 } /* if */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 else |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
236 { |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 comm->compressionType = noneID; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
238 } /* else */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 return(1); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 } /* read_comm_chunk */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
243 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
244 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
245 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
246 * The SSND chunk... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
247 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
248 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 typedef struct |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 Uint32 ckID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 Uint32 ckDataSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 Uint32 offset; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 Uint32 blockSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 * Then, comm->numSampleFrames sample frames. (It's better to get the |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 * length from numSampleFrames than from ckDataSize.) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 } ssnd_t; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 static int read_ssnd_chunk(SDL_RWops *rw, ssnd_t *ssnd) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 /* skip reading the chunk ID, since it was already read at this point... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 ssnd->ckID = ssndID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 if (SDL_RWread(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize), 1) != 1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
271 if (SDL_RWread(rw, &ssnd->offset, sizeof (ssnd->offset), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 ssnd->offset = SDL_SwapBE32(ssnd->offset); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
275 if (SDL_RWread(rw, &ssnd->blockSize, sizeof (ssnd->blockSize), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 /* Leave the SDL_RWops position indicator at the start of the samples */ |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
280 /* !!! FIXME: Int? Really? */ |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
281 if (SDL_RWseek(rw, (int) ssnd->offset, SEEK_CUR) == -1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 return(1); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 } /* read_ssnd_chunk */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
289 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
290 * Normal, uncompressed aiff handler... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
291 *****************************************************************************/ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
293 static Uint32 read_sample_fmt_normal(Sound_Sample *sample) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 Uint32 retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 aiff_t *a = (aiff_t *) internal->decoder_private; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 Uint32 max = (internal->buffer_size < (Uint32) a->bytesLeft) ? |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 internal->buffer_size : (Uint32) a->bytesLeft; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 assert(max > 0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 * We don't actually do any decoding, so we read the AIFF data |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 * directly into the internal buffer... |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 retval = SDL_RWread(internal->rw, internal->buffer, 1, max); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 a->bytesLeft -= retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 /* Make sure the read went smoothly... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 if ((retval == 0) || (a->bytesLeft == 0)) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 else if (retval == -1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 /* (next call this EAGAIN may turn into an EOF or error.) */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 else if (retval < internal->buffer_size) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 return(retval); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
323 } /* read_sample_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
324 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
325 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
326 static int rewind_sample_fmt_normal(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
327 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
328 /* no-op. */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
329 return(1); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
330 } /* rewind_sample_fmt_normal */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
331 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
332 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
333 static void free_fmt_normal(fmt_t *fmt) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
334 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
335 /* it's a no-op. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
336 } /* free_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
337 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
338 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
339 static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
340 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
341 /* (don't need to read more from the RWops...) */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
342 fmt->free = free_fmt_normal; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
343 fmt->read_sample = read_sample_fmt_normal; |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
344 fmt->rewind_sample = rewind_sample_fmt_normal; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
345 return(1); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
346 } /* read_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
347 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
348 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
349 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
350 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
351 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
352 * Everything else... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
353 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
354 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
355 static int AIFF_init(void) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
356 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
357 return(1); /* always succeeds. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
358 } /* AIFF_init */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
359 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
360 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
361 static void AIFF_quit(void) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
362 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
363 /* it's a no-op. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
364 } /* AIFF_quit */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
365 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
366 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
367 /* |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
368 * Sample rate is encoded as an "80 bit IEEE Standard 754 floating point |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
369 * number (Standard Apple Numeric Environment [SANE] data type Extended)". |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
370 * Whose bright idea was that? |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
371 * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
372 * This function was adapted from libsndfile, and while I do know a little |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
373 * bit about the IEEE floating point standard I don't pretend to fully |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
374 * understand this. |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
375 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
376 static Uint32 SANE_to_Uint32 (Uint8 *sanebuf) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
377 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
378 /* Is the frequency outside of what we can represent with Uint32? */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
379 if ( (sanebuf[0] & 0x80) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
380 || (sanebuf[0] <= 0x3F) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
381 || (sanebuf[0] > 0x40) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
382 || (sanebuf[0] == 0x40 && sanebuf[1] > 0x1C) ) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
383 return 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
384 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
385 return ((sanebuf[2] << 23) | (sanebuf[3] << 15) | (sanebuf[4] << 7) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
386 | (sanebuf[5] >> 1)) >> (29 - sanebuf[1]); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
387 } /* SANE_to_Uint32 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
388 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
389 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
390 static int find_chunk(SDL_RWops *rw, Uint32 id) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
391 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
392 Sint32 siz = 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
393 Uint32 _id = 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
394 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
395 while (1) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
396 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
397 BAIL_IF_MACRO(SDL_RWread(rw, &_id, sizeof (_id), 1) != 1, NULL, 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
398 if (SDL_SwapLE32(_id) == id) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
399 return(1); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
400 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
401 BAIL_IF_MACRO(SDL_RWread(rw, &siz, sizeof (siz), 1) != 1, NULL, 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
402 siz = SDL_SwapBE32(siz); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
403 assert(siz > 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
404 BAIL_IF_MACRO(SDL_RWseek(rw, siz, SEEK_CUR) == -1, NULL, 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
405 } /* while */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
406 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
407 return(0); /* shouldn't hit this, but just in case... */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
408 } /* find_chunk */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
409 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
410 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
411 static int read_fmt(SDL_RWops *rw, comm_t *c, fmt_t *fmt) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
412 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
413 fmt->type = c->compressionType; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
414 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
415 /* if it's in this switch statement, we support the format. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
416 switch (fmt->type) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
417 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
418 case noneID: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
419 SNDDBG(("AIFF: Appears to be uncompressed audio.\n")); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
420 return(read_fmt_normal(rw, fmt)); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
421 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
422 /* add other types here. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
423 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
424 default: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
425 SNDDBG(("AIFF: Format %lu is unknown.\n", |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
426 (unsigned int) fmt->type)); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
427 Sound_SetError("AIFF: Unsupported format"); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
428 return(0); /* not supported whatsoever. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
429 } /* switch */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
430 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
431 assert(0); /* shouldn't hit this point. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
432 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
433 } /* read_fmt */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
434 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
435 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
436 static int AIFF_open(Sound_Sample *sample, const char *ext) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
437 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
438 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
439 SDL_RWops *rw = internal->rw; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
440 Uint32 chunk_id; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
441 int bytes_per_sample; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
442 long pos; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
443 comm_t c; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
444 ssnd_t s; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
445 aiff_t *a; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
446 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
447 BAIL_IF_MACRO(SDL_ReadLE32(rw) != formID, "AIFF: Not a FORM file.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
448 SDL_ReadBE32(rw); /* throw the length away; we don't need it. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
449 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
450 chunk_id = SDL_ReadLE32(rw); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
451 BAIL_IF_MACRO(chunk_id != aiffID && chunk_id != aifcID, |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
452 "AIFF: Not an AIFF or AIFC file.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
453 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
454 /* Chunks may appear in any order, so we establish base camp here. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
455 pos = SDL_RWtell(rw); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
456 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
457 BAIL_IF_MACRO(!find_chunk(rw, commID), "AIFF: No common chunk.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
458 BAIL_IF_MACRO(!read_comm_chunk(rw, &c), |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
459 "AIFF: Can't read common chunk.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
460 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
461 sample->actual.channels = (Uint8) c.numChannels; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
462 sample->actual.rate = c.sampleRate; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
463 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
464 if (c.sampleSize <= 8) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
465 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
466 sample->actual.format = AUDIO_S8; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
467 bytes_per_sample = 1; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
468 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
469 else if (c.sampleSize <= 16) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
470 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
471 sample->actual.format = AUDIO_S16MSB; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
472 bytes_per_sample = 2; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
473 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
474 else |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
475 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
476 BAIL_MACRO("AIFF: Unsupported sample size.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
477 } /* else */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
478 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
479 BAIL_IF_MACRO(c.sampleRate == 0, "AIFF: Unsupported sample rate.", 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
480 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
481 a = (aiff_t *) malloc(sizeof(aiff_t)); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
482 BAIL_IF_MACRO(a == NULL, ERR_OUT_OF_MEMORY, 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
483 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
484 if (!read_fmt(rw, &c, &(a->fmt))) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
485 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
486 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
487 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
488 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
489 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
490 SDL_RWseek(rw, pos, SEEK_SET); /* if the seek fails, let it go... */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
491 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
492 if (!find_chunk(rw, ssndID)) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
493 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
494 Sound_SetError("AIFF: No sound data chunk."); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
495 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
496 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
497 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
498 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
499 if (!read_ssnd_chunk(rw, &s)) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
500 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
501 Sound_SetError("AIFF: Can't read sound data chunk."); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
502 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
503 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
504 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
505 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
506 a->fmt.total_bytes = a->bytesLeft = bytes_per_sample * c.numSampleFrames; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
507 a->fmt.data_starting_offset = SDL_RWtell(rw); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
508 internal->decoder_private = (void *) a; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
509 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
510 sample->flags = SOUND_SAMPLEFLAG_NONE; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
511 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
512 SNDDBG(("AIFF: Accepting data stream.\n")); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
513 return(1); /* we'll handle this data. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
514 } /* AIFF_open */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
515 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
516 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
517 static void AIFF_close(Sound_Sample *sample) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
518 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
519 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
520 aiff_t *a = (aiff_t *) internal->decoder_private; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
521 a->fmt.free(&(a->fmt)); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
522 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
523 } /* WAV_close */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
524 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
525 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
526 static Uint32 AIFF_read(Sound_Sample *sample) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
527 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
528 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
529 aiff_t *a = (aiff_t *) internal->decoder_private; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
530 return(a->fmt.read_sample(sample)); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 } /* AIFF_read */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
532 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
533 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
534 static int AIFF_rewind(Sound_Sample *sample) |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
535 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
536 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
|
537 aiff_t *a = (aiff_t *) internal->decoder_private; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
538 fmt_t *fmt = &a->fmt; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
539 int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
540 BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
541 a->bytesLeft = fmt->total_bytes; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
542 return(fmt->rewind_sample(sample)); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
543 } /* AIFF_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
544 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
545 #endif /* SOUND_SUPPORTS_AIFF */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
546 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
547 /* end of aiff.c ... */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
548 |