Mercurial > SDL_sound_CoreAudio
annotate decoders/aiff.c @ 377:cbb15ecf423a
WinCE (PocketPC) patches from Tyler.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 02 Jul 2002 03:58:24 +0000 |
parents | d76a34316c84 |
children | fb519e6028e3 |
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 |
106
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
54 #include "SDL_sound.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
55 |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
56 #define __SDL_SOUND_INTERNAL__ |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
57 #include "SDL_sound_internal.h" |
40de367eb59e
Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents:
104
diff
changeset
|
58 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
59 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
|
60 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
61 |
47
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
62 static int AIFF_init(void); |
ea58bc3b15d7
Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
63 static void AIFF_quit(void); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 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
|
65 static void AIFF_close(Sound_Sample *sample); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 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
|
67 static int AIFF_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
68 static int AIFF_seek(Sound_Sample *sample, Uint32 ms); |
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 */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
85 AIFF_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
86 AIFF_seek /* seek() method */ |
34
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 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
90 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
91 * 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
|
92 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
93 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
|
94 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
95 Uint32 type; |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
96 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
97 Uint32 total_bytes; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
98 Uint32 data_starting_offset; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
99 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
100 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
|
101 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
|
102 int (*rewind_sample)(Sound_Sample *sample); |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
103 int (*seek_sample)(Sound_Sample *sample, Uint32 ms); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
104 |
180
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 #if 0 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
107 /* |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
108 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
|
109 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
|
110 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
111 union |
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 struct |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
114 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
115 Uint16 cbSize; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
116 Uint16 wSamplesPerBlock; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
117 Uint16 wNumCoef; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
118 ADPCMCOEFSET *aCoeff; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
119 } adpcm; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
120 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
121 /* 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
|
122 } fmt; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
123 #endif |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
124 } fmt_t; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
125 |
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 typedef struct |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
128 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
129 fmt_t fmt; |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 Sint32 bytesLeft; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 } aiff_t; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
134 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 /* Chunk management code... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
137 #define formID 0x4D524F46 /* "FORM", in ascii. */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 #define aiffID 0x46464941 /* "AIFF", in ascii. */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 #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
|
140 #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
|
141 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
180
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 * The COMM chunk... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
145 *****************************************************************************/ |
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 #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
|
148 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
149 /* format/compression types... */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
150 #define noneID 0x454E4F4E /* "NONE", in ascii. */ |
34
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 typedef struct |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 Uint32 ckID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 Uint32 ckDataSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 Uint16 numChannels; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 Uint32 numSampleFrames; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 Uint16 sampleSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 Uint32 sampleRate; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 * 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
|
162 * interested the allowed compression types are supposed to be |
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 * compressionType compressionName meaning |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 * --------------------------------------------------------------- |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 * 'NONE' "not compressed" uncompressed, that is, |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 * straight digitized samples |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 * '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
|
169 * Compression / Expansion) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 * '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
|
171 * Compression / Expansion) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 * '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
|
173 * Compression / Expansion |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 * '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
|
175 * Compression / Expansion |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 * 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
|
178 * 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
|
179 * 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
|
180 * 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
|
181 * 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
|
182 * byte is not reflected in the count." |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 * |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 * 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
|
185 * good as mine. |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 Uint32 compressionType; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 #if 0 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 pstring compressionName; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 #endif |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 } comm_t; |
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 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 * 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
|
196 * 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
|
197 */ |
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 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
|
200 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 Uint8 sampleRate[10]; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 /* 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
|
204 comm->ckID = commID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 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
|
207 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 comm->ckDataSize = SDL_SwapBE32(comm->ckDataSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 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
|
211 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 comm->numChannels = SDL_SwapBE16(comm->numChannels); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
214 if (SDL_RWread(rw, &comm->numSampleFrames, |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
215 sizeof (comm->numSampleFrames), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 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
|
220 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 comm->sampleSize = SDL_SwapBE16(comm->sampleSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
223 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
|
224 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 comm->sampleRate = SANE_to_Uint32(sampleRate); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 if (comm->ckDataSize > sizeof(comm->numChannels) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 + sizeof(comm->numSampleFrames) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 + sizeof(comm->sampleSize) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 + sizeof(sampleRate)) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 { |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
232 if (SDL_RWread(rw, &comm->compressionType, |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
233 sizeof (comm->compressionType), 1) != 1) |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 comm->compressionType = SDL_SwapBE32(comm->compressionType); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 } /* if */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 else |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
238 { |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 comm->compressionType = noneID; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
240 } /* else */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 return(1); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 } /* read_comm_chunk */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
180
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 |
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 * The SSND chunk... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
249 *****************************************************************************/ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
250 |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 typedef struct |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 Uint32 ckID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 Uint32 ckDataSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 Uint32 offset; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 Uint32 blockSize; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 * 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
|
259 * length from numSampleFrames than from ckDataSize.) |
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 } ssnd_t; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
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 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
|
265 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 /* 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
|
267 ssnd->ckID = ssndID; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 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
|
270 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
273 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
|
274 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 ssnd->offset = SDL_SwapBE32(ssnd->offset); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
41
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
277 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
|
278 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 /* 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
|
282 /* !!! FIXME: Int? Really? */ |
0d5ff5679523
Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents:
34
diff
changeset
|
283 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
|
284 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 return(1); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 } /* read_ssnd_chunk */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
291 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
292 * Normal, uncompressed aiff handler... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
293 *****************************************************************************/ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
295 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
|
296 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 Uint32 retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 aiff_t *a = (aiff_t *) internal->decoder_private; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 Uint32 max = (internal->buffer_size < (Uint32) a->bytesLeft) ? |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 internal->buffer_size : (Uint32) a->bytesLeft; |
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 assert(max > 0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 * 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
|
307 * directly into the internal buffer... |
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 retval = SDL_RWread(internal->rw, internal->buffer, 1, max); |
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 a->bytesLeft -= retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 /* Make sure the read went smoothly... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 if ((retval == 0) || (a->bytesLeft == 0)) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 else if (retval == -1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 /* (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
|
321 else if (retval < internal->buffer_size) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 return(retval); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
325 } /* read_sample_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
326 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
327 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
328 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
|
329 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
330 /* no-op. */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
331 return(1); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
332 } /* rewind_sample_fmt_normal */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
333 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
334 |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
335 static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms) |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
336 { |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
337 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
338 aiff_t *a = (aiff_t *) internal->decoder_private; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
339 fmt_t *fmt = &a->fmt; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
340 int offset = __Sound_convertMsToBytePos(&sample->actual, ms); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
341 int pos = (int) (fmt->data_starting_offset + offset); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
342 int rc = SDL_RWseek(internal->rw, pos, SEEK_SET); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
343 BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
344 a->bytesLeft = fmt->total_bytes - offset; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
345 return(1); /* success. */ |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
346 } /* seek_sample_fmt_normal */ |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
347 |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
348 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
349 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
|
350 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
351 /* 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
|
352 } /* free_fmt_normal */ |
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 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
|
356 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
357 /* (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
|
358 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
|
359 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
|
360 fmt->rewind_sample = rewind_sample_fmt_normal; |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
361 fmt->seek_sample = seek_sample_fmt_normal; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
362 return(1); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
363 } /* read_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
364 |
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 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
369 * Everything else... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
370 *****************************************************************************/ |
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 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
|
373 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
374 return(1); /* always succeeds. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
375 } /* AIFF_init */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
376 |
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 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
|
379 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
380 /* 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
|
381 } /* AIFF_quit */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
382 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
383 |
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 * 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
|
386 * 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
|
387 * 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
|
388 * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
389 * 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
|
390 * 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
|
391 * understand this. |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
392 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
393 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
|
394 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
395 /* 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
|
396 if ( (sanebuf[0] & 0x80) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
397 || (sanebuf[0] <= 0x3F) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
398 || (sanebuf[0] > 0x40) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
399 || (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
|
400 return 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
401 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
402 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
|
403 | (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
|
404 } /* SANE_to_Uint32 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
405 |
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 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
|
408 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
409 Sint32 siz = 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
410 Uint32 _id = 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
411 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
412 while (1) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
413 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
414 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
|
415 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
|
416 return(1); |
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 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
|
419 siz = SDL_SwapBE32(siz); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
420 assert(siz > 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
421 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
|
422 } /* while */ |
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 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
|
425 } /* find_chunk */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
426 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
427 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
428 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
|
429 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
430 fmt->type = c->compressionType; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
431 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
432 /* 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
|
433 switch (fmt->type) |
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 case noneID: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
436 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
|
437 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
|
438 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
439 /* add other types here. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
440 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
441 default: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
442 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
|
443 (unsigned int) fmt->type)); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
444 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
|
445 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
|
446 } /* switch */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
447 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
448 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
|
449 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
450 } /* read_fmt */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
451 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
452 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
453 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
|
454 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
455 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
|
456 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
|
457 Uint32 chunk_id; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
458 int bytes_per_sample; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
459 long pos; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
460 comm_t c; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
461 ssnd_t s; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
462 aiff_t *a; |
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 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
|
465 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
|
466 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
467 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
|
468 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
|
469 "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
|
470 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
471 /* 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
|
472 pos = SDL_RWtell(rw); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
473 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
474 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
|
475 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
|
476 "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
|
477 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
478 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
|
479 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
|
480 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
481 if (c.sampleSize <= 8) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
482 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
483 sample->actual.format = AUDIO_S8; |
369
d76a34316c84
Fixed to handle stereo AIFF files.
Ryan C. Gordon <icculus@icculus.org>
parents:
332
diff
changeset
|
484 bytes_per_sample = c.numChannels; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
485 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
486 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
|
487 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
488 sample->actual.format = AUDIO_S16MSB; |
369
d76a34316c84
Fixed to handle stereo AIFF files.
Ryan C. Gordon <icculus@icculus.org>
parents:
332
diff
changeset
|
489 bytes_per_sample = 2 * c.numChannels; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
490 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
491 else |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
492 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
493 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
|
494 } /* else */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
495 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
496 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
|
497 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
498 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
|
499 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
|
500 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
501 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
|
502 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
503 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
504 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
505 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
506 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
507 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
|
508 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
509 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
|
510 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
511 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
|
512 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
513 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
514 } /* if */ |
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 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
|
517 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
518 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
|
519 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
520 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
521 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
522 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
527 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
528 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
529 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
|
530 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
|
531 } /* AIFF_open */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
532 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
533 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
534 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
|
535 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 free(a); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
540 } /* AIFF_close */ |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
541 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
542 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
543 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
|
544 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
545 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
|
546 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
|
547 return(a->fmt.read_sample(sample)); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
548 } /* AIFF_read */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
549 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
550 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
551 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
|
552 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 } /* AIFF_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
561 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
562 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
563 static int AIFF_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
564 { |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
565 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
566 aiff_t *a = (aiff_t *) internal->decoder_private; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
567 return(a->fmt.seek_sample(sample, ms)); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
568 } /* AIFF_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
569 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
570 #endif /* SOUND_SUPPORTS_AIFF */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
571 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
572 /* end of aiff.c ... */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
573 |