annotate decoders/shn.c @ 100:6d9fdec2f708

added config.h, added --enable-debug flag, various other changes to the build system
author fingolfin
date Wed, 03 Oct 2001 12:25:34 +0000
parents 155ab2a427ca
children c08794028df4
rev   line source
86
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Shorten decoder for SDL_sound.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles Shorten-compressed waveforms. Despite the fact that
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * SHNs are generally used in online trading communities, they tend to be
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * much bigger than MP3s. If an MP3 crunches the waveform to 10-20 percent
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 * of its original size, SHNs only go to about 50-60%. Why do the Phish fans
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * of the world use this format then? Rabid music traders appreciate the
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * sound quality; SHNs, unlike MP3s, do not throw away any part of the
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 * waveform. Yes, there are people that notice this, and further more, they
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 * demand it...and if they can't get a good transfer of those larger files
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 * over the 'net, they haven't underestimated the bandwidth of CDs travelling
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 * the world through the postal system.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 * Shorten homepage: http://www.softsound.com/Shorten.html
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 * The Shorten format was gleaned from the shorten codebase, by Tony
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 * Robinson and SoftSound Limited, but none of their code was used here.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 * Please see the file LICENSE in the source's root directory.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 *
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #if (defined SOUND_SUPPORTS_SHN)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
100
6d9fdec2f708 added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents: 86
diff changeset
46 #define __SDL_SOUND_INTERNAL__
6d9fdec2f708 added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents: 86
diff changeset
47 #include "SDL_sound_internal.h"
6d9fdec2f708 added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents: 86
diff changeset
48
86
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #include <stdio.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #include <stdlib.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 #include <string.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #include <assert.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include "SDL_sound.h"
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 static int SHN_init(void);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static void SHN_quit(void);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static int SHN_open(Sound_Sample *sample, const char *ext);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static void SHN_close(Sound_Sample *sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 static Uint32 SHN_read(Sound_Sample *sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN =
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 "SHN",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 "Shorten-compressed audio data",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 "Ryan C. Gordon <icculus@clutteredmind.org>",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 "http://www.icculus.org/SDL_sound/"
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 },
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 SHN_init, /* init() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 SHN_quit, /* quit() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 SHN_open, /* open() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 SHN_close, /* close() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 SHN_read /* read() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 };
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 static int SHN_init(void)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 return(1); /* initialization always successful. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 } /* SHN_init */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 static void SHN_quit(void)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 /* it's a no-op. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 } /* SHN_quit */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 static Uint32 mask_table[] =
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 };
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 #define MAGIC_NUM 0x676B6A61 /* looks like "ajkg" as chars. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 /*
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 * Look through the whole file for a SHN magic number. This is costly, so
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 * it should only be done if the user SWEARS they have a Shorten stream...
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 static inline int extended_shn_magic_search(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Uint32 word = 0;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 Uint8 ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 while (1)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 word = ((word << 8) & 0xFFFFFF00) | ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 if (SDL_SwapLE32(word) == MAGIC_NUM)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 } /* if */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 } /* while */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 } /* extended_shn_magic_search */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 /* look for the magic number in the RWops and see what kind of file this is. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 static inline int determine_shn_version(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 Uint32 magic;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 Uint8 ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 /*
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 * Apparently the magic number can start at any byte offset in the file,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 * and we should just discard prior data, but I'm going to restrict it
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 * to offset zero for now, so we don't chug down every file that might
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 * happen to pass through here. If the extension is explicitly "SHN", we
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 * check the whole stream, though.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 if (__Sound_strcasecmp(ext, "shn") == 0)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 return(extended_shn_magic_search(sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 BAIL_IF_MACRO(SDL_RWread(rw, &magic, sizeof (magic), 1) != 1, NULL, -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 BAIL_IF_MACRO(SDL_SwapLE32(magic) != MAGIC_NUM, "SHN: Not a SHN file", -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 BAIL_IF_MACRO(SDL_RWread(rw, &ch, sizeof (ch), 1) != 1, NULL, -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 BAIL_IF_MACRO(ch > 3, "SHN: Unsupported file version", -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 } /* determine_shn_version */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 static int SHN_open(Sound_Sample *sample, const char *ext)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 SDL_RWops *rw = internal->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 int shn_version = determine_shn_version(sample, ext);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 int mean = MEAN_VERSION2;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 BAIL_IF_MACRO(shn_version == -1, NULL, 0);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 if (shn_version < 2) /* downgrade? */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 mean = MEAN_VERSION0;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 SNDDBG(("SHN: Accepting data stream.\n"));
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 set up sample->actual;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 sample->flags = SOUND_SAMPLEFLAG_NONE;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 return(1); /* we'll handle this data. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 } /* SHN_open */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 static void SHN_close(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 clean up anything you put into internal->decoder_private;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 } /* SHN_close */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 static Uint32 SHN_read(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 Uint32 retval;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 /*
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 * We don't actually do any decoding, so we read the fmt data
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 * directly into the internal buffer...
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 retval = SDL_RWread(internal->rw, internal->buffer,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 1, internal->buffer_size);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 (or whatever. Do some decoding here...)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 /* Make sure the read went smoothly... */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 if (retval == 0)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 sample->flags |= SOUND_SAMPLEFLAG_EOF;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 else if (retval == -1)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 /* (next call this EAGAIN may turn into an EOF or error.) */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 else if (retval < internal->buffer_size)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 (or whatever. retval == number of bytes you put in internal->buffer).
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 return(retval);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 } /* SHN_read */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 #endif /* defined SOUND_SUPPORTS_SHN */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 /* end of shn.c ... */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216