Mercurial > SDL_sound_CoreAudio
annotate decoders/aiff.c @ 556:1c7d570fcee8 stable-1.0
Abandoning CHANGELOG.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 27 Jan 2009 14:09:55 -0500 |
parents | 45ee760a6f5a |
children |
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 * |
535
45ee760a6f5a
Converted all text encoding from ISO-8859-1 to UTF-8.
Ryan C. Gordon <icculus@icculus.org>
parents:
400
diff
changeset
|
41 * This file was written by Torbjörn Andersson. (d91tan@Update.UU.SE) |
34
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", |
535
45ee760a6f5a
Converted all text encoding from ISO-8859-1 to UTF-8.
Ryan C. Gordon <icculus@icculus.org>
parents:
400
diff
changeset
|
76 "Torbjörn Andersson <d91tan@Update.UU.SE>", |
34
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 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
|
283 return(0); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 return(1); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 } /* read_ssnd_chunk */ |
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 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
290 /***************************************************************************** |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
291 * Normal, uncompressed aiff handler... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
292 *****************************************************************************/ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
294 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
|
295 { |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 Uint32 retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 aiff_t *a = (aiff_t *) internal->decoder_private; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 Uint32 max = (internal->buffer_size < (Uint32) a->bytesLeft) ? |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 internal->buffer_size : (Uint32) a->bytesLeft; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 assert(max > 0); |
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 /* |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 * 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
|
306 * directly into the internal buffer... |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 retval = SDL_RWread(internal->rw, internal->buffer, 1, max); |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 a->bytesLeft -= retval; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 /* Make sure the read went smoothly... */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 if ((retval == 0) || (a->bytesLeft == 0)) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 else if (retval == -1) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 /* (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
|
320 else if (retval < internal->buffer_size) |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 return(retval); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
324 } /* read_sample_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
325 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
326 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
327 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
|
328 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
329 /* no-op. */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
330 return(1); |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
331 } /* rewind_sample_fmt_normal */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
332 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
333 |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
334 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
|
335 { |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
336 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
337 aiff_t *a = (aiff_t *) internal->decoder_private; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
338 fmt_t *fmt = &a->fmt; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
339 int offset = __Sound_convertMsToBytePos(&sample->actual, ms); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
340 int pos = (int) (fmt->data_starting_offset + offset); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
341 int rc = SDL_RWseek(internal->rw, pos, SEEK_SET); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
342 BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0); |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
343 a->bytesLeft = fmt->total_bytes - offset; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
344 return(1); /* success. */ |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
345 } /* seek_sample_fmt_normal */ |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
346 |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
347 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
348 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
|
349 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
350 /* 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
|
351 } /* free_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
352 |
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 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
|
355 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
356 /* (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
|
357 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
|
358 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
|
359 fmt->rewind_sample = rewind_sample_fmt_normal; |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
360 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
|
361 return(1); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
362 } /* read_fmt_normal */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
363 |
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 * Everything else... * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
369 *****************************************************************************/ |
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 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
|
372 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
373 return(1); /* always succeeds. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
374 } /* AIFF_init */ |
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 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
377 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
|
378 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
379 /* 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
|
380 } /* AIFF_quit */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
381 |
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 * 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
|
385 * 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
|
386 * 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
|
387 * |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
388 * 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
|
389 * 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
|
390 * understand this. |
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 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
|
393 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
394 /* 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
|
395 if ( (sanebuf[0] & 0x80) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
396 || (sanebuf[0] <= 0x3F) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
397 || (sanebuf[0] > 0x40) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
398 || (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
|
399 return 0; |
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 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
|
402 | (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
|
403 } /* SANE_to_Uint32 */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
404 |
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 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
|
407 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
408 Sint32 siz = 0; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
409 Uint32 _id = 0; |
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 while (1) |
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 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
|
414 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
|
415 return(1); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
416 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
417 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
|
418 siz = SDL_SwapBE32(siz); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
419 assert(siz > 0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
420 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
|
421 } /* while */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
422 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
423 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
|
424 } /* find_chunk */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
425 |
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 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
|
428 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
429 fmt->type = c->compressionType; |
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 /* 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
|
432 switch (fmt->type) |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
433 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
434 case noneID: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
435 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
|
436 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
|
437 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
438 /* add other types here. */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
439 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
440 default: |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
441 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
|
442 (unsigned int) fmt->type)); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
443 BAIL_MACRO("AIFF: Unsupported format", 0); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
444 } /* switch */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
445 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
446 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
|
447 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
448 } /* read_fmt */ |
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 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
451 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
|
452 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
453 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
|
454 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
|
455 Uint32 chunk_id; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
456 int bytes_per_sample; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
457 long pos; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
458 comm_t c; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
459 ssnd_t s; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
460 aiff_t *a; |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
461 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
462 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
|
463 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
|
464 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
465 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
|
466 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
|
467 "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
|
468 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
469 /* 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
|
470 pos = SDL_RWtell(rw); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
471 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
472 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
|
473 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
|
474 "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
|
475 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
476 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
|
477 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
|
478 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
479 if (c.sampleSize <= 8) |
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 sample->actual.format = AUDIO_S8; |
369
d76a34316c84
Fixed to handle stereo AIFF files.
Ryan C. Gordon <icculus@icculus.org>
parents:
332
diff
changeset
|
482 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
|
483 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
484 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
|
485 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
486 sample->actual.format = AUDIO_S16MSB; |
369
d76a34316c84
Fixed to handle stereo AIFF files.
Ryan C. Gordon <icculus@icculus.org>
parents:
332
diff
changeset
|
487 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
|
488 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
489 else |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
490 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
491 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
|
492 } /* else */ |
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 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
|
495 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
496 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
|
497 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
|
498 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
499 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
|
500 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
501 free(a); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
502 return(0); |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
503 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
504 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
505 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
|
506 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
507 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
|
508 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
509 free(a); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
510 BAIL_MACRO("AIFF: No sound data chunk.", 0); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
511 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
512 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
513 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
|
514 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
515 free(a); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
377
diff
changeset
|
516 BAIL_MACRO("AIFF: Can't read sound data chunk.", 0); |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
517 } /* if */ |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
518 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
523 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
|
524 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
525 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
|
526 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
|
527 } /* AIFF_open */ |
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 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
530 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
|
531 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
532 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
|
533 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
|
534 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
|
535 free(a); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
536 } /* AIFF_close */ |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
537 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
538 |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
539 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
|
540 { |
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
541 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
|
542 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
|
543 return(a->fmt.read_sample(sample)); |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
544 } /* AIFF_read */ |
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
546 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
547 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
|
548 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 } /* AIFF_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
184
diff
changeset
|
557 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
558 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
559 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
|
560 { |
332
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
561 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
562 aiff_t *a = (aiff_t *) internal->decoder_private; |
8ba541e81c1e
seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents:
306
diff
changeset
|
563 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
|
564 } /* AIFF_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
565 |
64
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
566 #endif /* SOUND_SUPPORTS_AIFF */ |
40006625142a
Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
62
diff
changeset
|
567 |
180
db3f0ee7aac0
Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents:
149
diff
changeset
|
568 /* end of aiff.c ... */ |
34
938ef560c7bf
Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |