annotate decoders/aiff.c @ 360:c984aa6990f7

Fixes and enhancements from Frank Ranostaj.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 12 Jun 2002 08:35:23 +0000
parents 8ba541e81c1e
children d76a34316c84
rev   line source
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * AIFF decoder for SDL_sound
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * [Insert something profound about the AIFF file format here.]
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * This code was ripped from a decoder I had written for SDL_mixer, which was
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * based on SDL_mixer's old AIFF music loader. (This loader was unfortunately
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * completely broken, but it was still useful because all the pieces were
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * still there, so to speak.)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 * When rewriting it for SDL_sound, I changed its structure to be more like
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 * the WAV loader Ryan wrote. Had they not both been part of the same project
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 * it would have been embarrassing how similar they are.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 * It is not the most feature-complete AIFF loader the world has ever seen.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 * For instance, it only makes a token attempt at implementing the AIFF-C
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 * standard; basically the parts of it that I can easily understand and test.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 * It's a start, though.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 *
184
47cc2de2ae36 Changed reference to "LICENSE" file to "COPYING".
Ryan C. Gordon <icculus@icculus.org>
parents: 180
diff changeset
39 * Please see the file COPYING in the source's root directory.
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 * This file was written by Torbjörn Andersson. (d91tan@Update.UU.SE)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
106
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
44 #if HAVE_CONFIG_H
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
45 # include <config.h>
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
46 #endif
100
6d9fdec2f708 added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents: 64
diff changeset
47
104
103cfcb3c014 Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
48 #ifdef SOUND_SUPPORTS_AIFF
103cfcb3c014 Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
49
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #include <stdio.h>
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 #include <stdlib.h>
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #include <string.h>
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include <assert.h>
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
106
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
55 #include "SDL_sound.h"
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
56
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
57 #define __SDL_SOUND_INTERNAL__
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
58 #include "SDL_sound_internal.h"
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
59
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
60 static Uint32 SANE_to_Uint32 (Uint8 *sanebuf);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
61
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
62
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
63 static int AIFF_init(void);
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
64 static void AIFF_quit(void);
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 static int AIFF_open(Sound_Sample *sample, const char *ext);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 static void AIFF_close(Sound_Sample *sample);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 static Uint32 AIFF_read(Sound_Sample *sample);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
68 static int AIFF_rewind(Sound_Sample *sample);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
69 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
70
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 116
diff changeset
71 static const char *extensions_aiff[] = { "AIFF", NULL };
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 116
diff changeset
75 extensions_aiff,
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 "Audio Interchange File Format",
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 "Torbjörn Andersson <d91tan@Update.UU.SE>",
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 "http://www.icculus.org/SDL_sound/"
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 },
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
81 AIFF_init, /* init() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
82 AIFF_quit, /* quit() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
83 AIFF_open, /* open() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
84 AIFF_close, /* close() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
85 AIFF_read, /* read() method */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
86 AIFF_rewind, /* rewind() method */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
87 AIFF_seek /* seek() method */
34
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
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
91 /*****************************************************************************
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
92 * 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
93 *****************************************************************************/
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
94 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
95 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
96 Uint32 type;
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
97
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
98 Uint32 total_bytes;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
99 Uint32 data_starting_offset;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
100
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
101 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
102 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
103 int (*rewind_sample)(Sound_Sample *sample);
332
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
104 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
105
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
106
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
107 #if 0
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
108 /*
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
109 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
110 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
111 */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
112 union
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
113 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
114 struct
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
115 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
116 Uint16 cbSize;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
117 Uint16 wSamplesPerBlock;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
118 Uint16 wNumCoef;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
119 ADPCMCOEFSET *aCoeff;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
120 } adpcm;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
121
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
122 /* 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
123 } fmt;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
124 #endif
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
125 } fmt_t;
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
128 typedef struct
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
129 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
130 fmt_t fmt;
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 Sint32 bytesLeft;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 } aiff_t;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
135
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 /* Chunk management code... */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
138 #define formID 0x4D524F46 /* "FORM", in ascii. */
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 #define aiffID 0x46464941 /* "AIFF", in ascii. */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 #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
141 #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
142
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
144 /*****************************************************************************
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
145 * The COMM chunk... *
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
148 #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
149
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
150 /* format/compression types... */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
151 #define noneID 0x454E4F4E /* "NONE", in ascii. */
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 typedef struct
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 Uint32 ckID;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 Uint32 ckDataSize;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 Uint16 numChannels;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 Uint32 numSampleFrames;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 Uint16 sampleSize;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 Uint32 sampleRate;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 * 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
163 * interested the allowed compression types are supposed to be
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 * compressionType compressionName meaning
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 * ---------------------------------------------------------------
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 * 'NONE' "not compressed" uncompressed, that is,
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 * straight digitized samples
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 * '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
170 * Compression / Expansion)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 * '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
172 * Compression / Expansion)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 * '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
174 * Compression / Expansion
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 * '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
176 * Compression / Expansion
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 * 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
179 * 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
180 * 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
181 * 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
182 * 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
183 * byte is not reflected in the count."
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 *
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 * 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
186 * good as mine.
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 Uint32 compressionType;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 #if 0
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 pstring compressionName;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 #endif
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 } comm_t;
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 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 * 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
197 * 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
198 */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 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
201 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 Uint8 sampleRate[10];
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 /* 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
205 comm->ckID = commID;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 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
208 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 comm->ckDataSize = SDL_SwapBE32(comm->ckDataSize);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 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
212 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 comm->numChannels = SDL_SwapBE16(comm->numChannels);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
41
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
215 if (SDL_RWread(rw, &comm->numSampleFrames,
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
216 sizeof (comm->numSampleFrames), 1) != 1)
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 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
221 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 comm->sampleSize = SDL_SwapBE16(comm->sampleSize);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223
41
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
224 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
225 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 comm->sampleRate = SANE_to_Uint32(sampleRate);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 if (comm->ckDataSize > sizeof(comm->numChannels)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 + sizeof(comm->numSampleFrames)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 + sizeof(comm->sampleSize)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 + sizeof(sampleRate))
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 {
41
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
233 if (SDL_RWread(rw, &comm->compressionType,
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
234 sizeof (comm->compressionType), 1) != 1)
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 comm->compressionType = SDL_SwapBE32(comm->compressionType);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 } /* if */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 else
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
239 {
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 comm->compressionType = noneID;
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
241 } /* else */
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 return(1);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 } /* read_comm_chunk */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245
180
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 /*****************************************************************************
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
249 * The SSND chunk... *
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
250 *****************************************************************************/
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
251
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 typedef struct
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 Uint32 ckID;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 Uint32 ckDataSize;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 Uint32 offset;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 Uint32 blockSize;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 * 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
260 * length from numSampleFrames than from ckDataSize.)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 } ssnd_t;
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
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 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
266 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 /* 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
268 ssnd->ckID = ssndID;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 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
271 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273
41
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
274 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
275 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 ssnd->offset = SDL_SwapBE32(ssnd->offset);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277
41
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
278 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
279 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 /* 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
283 /* !!! FIXME: Int? Really? */
0d5ff5679523 Cleanups from Torbj�rn Andersson.
Ryan C. Gordon <icculus@icculus.org>
parents: 34
diff changeset
284 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
285 return(0);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 return(1);
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 } /* read_ssnd_chunk */
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
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
292 /*****************************************************************************
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
293 * Normal, uncompressed aiff handler... *
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
294 *****************************************************************************/
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
296 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
297 {
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 Uint32 retval;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 aiff_t *a = (aiff_t *) internal->decoder_private;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 Uint32 max = (internal->buffer_size < (Uint32) a->bytesLeft) ?
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 internal->buffer_size : (Uint32) a->bytesLeft;
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 assert(max > 0);
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 /*
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 * 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
308 * directly into the internal buffer...
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 retval = SDL_RWread(internal->rw, internal->buffer, 1, max);
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 a->bytesLeft -= retval;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 /* Make sure the read went smoothly... */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 if ((retval == 0) || (a->bytesLeft == 0))
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 sample->flags |= SOUND_SAMPLEFLAG_EOF;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 else if (retval == -1)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 /* (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
322 else if (retval < internal->buffer_size)
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 return(retval);
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
326 } /* read_sample_fmt_normal */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
327
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
328
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
329 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
330 {
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
331 /* no-op. */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
332 return(1);
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
333 } /* rewind_sample_fmt_normal */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
334
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
335
332
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
336 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
337 {
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
338 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
339 aiff_t *a = (aiff_t *) internal->decoder_private;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
340 fmt_t *fmt = &a->fmt;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
341 int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
342 int pos = (int) (fmt->data_starting_offset + offset);
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
343 int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
344 BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
345 a->bytesLeft = fmt->total_bytes - offset;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
346 return(1); /* success. */
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
347 } /* seek_sample_fmt_normal */
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
348
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
349
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
350 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
351 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
352 /* 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
353 } /* free_fmt_normal */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
356 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
357 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
358 /* (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
359 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
360 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
361 fmt->rewind_sample = rewind_sample_fmt_normal;
332
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
362 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
363 return(1);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
364 } /* read_fmt_normal */
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 /*****************************************************************************
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
370 * Everything else... *
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
373 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
374 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
375 return(1); /* always succeeds. */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
376 } /* AIFF_init */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
379 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
380 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
381 /* 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
382 } /* AIFF_quit */
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 /*
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
386 * 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
387 * 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
388 * 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
389 *
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
390 * 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
391 * 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
392 * understand this.
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 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
395 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
396 /* 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
397 if ( (sanebuf[0] & 0x80)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
398 || (sanebuf[0] <= 0x3F)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
399 || (sanebuf[0] > 0x40)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
400 || (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
401 return 0;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
402
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
403 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
404 | (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
405 } /* SANE_to_Uint32 */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
408 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
409 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
410 Sint32 siz = 0;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
411 Uint32 _id = 0;
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 while (1)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
414 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
415 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
416 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
417 return(1);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
418
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
419 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
420 siz = SDL_SwapBE32(siz);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
421 assert(siz > 0);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
422 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
423 } /* while */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
424
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
425 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
426 } /* find_chunk */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
429 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
430 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
431 fmt->type = c->compressionType;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
432
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
433 /* 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
434 switch (fmt->type)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
435 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
436 case noneID:
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
437 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
438 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
439
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
440 /* add other types here. */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
441
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
442 default:
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
443 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
444 (unsigned int) fmt->type));
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
445 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
446 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
447 } /* switch */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
448
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
449 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
450 return(0);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
451 } /* read_fmt */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
454 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
455 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
456 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
457 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
458 Uint32 chunk_id;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
459 int bytes_per_sample;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
460 long pos;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
461 comm_t c;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
462 ssnd_t s;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
463 aiff_t *a;
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 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
466 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
467
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
468 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
469 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
470 "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
471
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
472 /* 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
473 pos = SDL_RWtell(rw);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
474
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
475 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
476 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
477 "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
478
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
479 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
480 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
481
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
482 if (c.sampleSize <= 8)
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
483 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
484 sample->actual.format = AUDIO_S8;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
485 bytes_per_sample = 1;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
486 } /* if */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
487 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
488 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
489 sample->actual.format = AUDIO_S16MSB;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
490 bytes_per_sample = 2;
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
491 } /* if */
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_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
495 } /* else */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
496
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
497 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
498
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
499 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
500 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
501
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
502 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
503 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
504 free(a);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
505 return(0);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
506 } /* if */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
507
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
508 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
509
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
510 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
511 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
512 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
513 free(a);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
514 return(0);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
515 } /* if */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
516
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
517 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
518 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
519 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
520 free(a);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
521 return(0);
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
522 } /* if */
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
523
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
524 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
525 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
526 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
527
332
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
528 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
529
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
530 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
531 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
532 } /* AIFF_open */
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
535 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
536 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
537 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
538 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
539 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
540 free(a);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
541 } /* AIFF_close */
180
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
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
544 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
545 {
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
546 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
547 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
548 return(a->fmt.read_sample(sample));
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 } /* AIFF_read */
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
551
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
552 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
553 {
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
554 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
555 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
556 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
557 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
558 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
559 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
560 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
561 } /* AIFF_rewind */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 184
diff changeset
562
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
563
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
564 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
565 {
332
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
566 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
567 aiff_t *a = (aiff_t *) internal->decoder_private;
8ba541e81c1e seek method implementation.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
568 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
569 } /* AIFF_seek */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
570
64
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
571 #endif /* SOUND_SUPPORTS_AIFF */
40006625142a Changes in preparation of autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 62
diff changeset
572
180
db3f0ee7aac0 Modified to more easily allow for different compression types.
Ryan C. Gordon <icculus@icculus.org>
parents: 149
diff changeset
573 /* end of aiff.c ... */
34
938ef560c7bf Initial add. Thanks, Torbj�rn!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574