annotate decoders/shn.c @ 93:69352e3cc996

Updated.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 01 Oct 2001 09:12:44 +0000
parents 155ab2a427ca
children 6d9fdec2f708
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
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #include <stdio.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #include <stdlib.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 #include <string.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #include <assert.h>
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #include "SDL_sound.h"
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #define __SDL_SOUND_INTERNAL__
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include "SDL_sound_internal.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 static int SHN_init(void);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 static void SHN_quit(void);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static int SHN_open(Sound_Sample *sample, const char *ext);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static void SHN_close(Sound_Sample *sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static Uint32 SHN_read(Sound_Sample *sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN =
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 {
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 "SHN",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 "Shorten-compressed audio data",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 "Ryan C. Gordon <icculus@clutteredmind.org>",
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 "http://www.icculus.org/SDL_sound/"
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 },
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 SHN_init, /* init() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 SHN_quit, /* quit() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 SHN_open, /* open() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 SHN_close, /* close() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 SHN_read /* read() method */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 };
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 static int SHN_init(void)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 return(1); /* initialization always successful. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 } /* SHN_init */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
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 static void SHN_quit(void)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 /* it's a no-op. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 } /* SHN_quit */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
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 static Uint32 mask_table[] =
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 };
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 #define MAGIC_NUM 0x676B6A61 /* looks like "ajkg" as chars. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
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 * 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
105 * 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
106 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 static inline int extended_shn_magic_search(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 Uint32 word = 0;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 Uint8 ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 while (1)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 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
116 word = ((word << 8) & 0xFFFFFF00) | ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 if (SDL_SwapLE32(word) == MAGIC_NUM)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 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
120 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 } /* if */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 } /* while */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 } /* extended_shn_magic_search */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
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 /* 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
129 static inline int determine_shn_version(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 SDL_RWops *rw = ((Sound_SampleInternal *) sample->opaque)->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 Uint32 magic;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 Uint8 ch;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134
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 * 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
137 * 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
138 * 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
139 * happen to pass through here. If the extension is explicitly "SHN", we
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 * check the whole stream, though.
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 */
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 if (__Sound_strcasecmp(ext, "shn") == 0)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 return(extended_shn_magic_search(sample);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 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
147 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
148 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
149 BAIL_IF_MACRO(ch > 3, "SHN: Unsupported file version", -1);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 return((int) ch);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 } /* determine_shn_version */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153
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 static int SHN_open(Sound_Sample *sample, const char *ext)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 SDL_RWops *rw = internal->rw;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 int shn_version = determine_shn_version(sample, ext);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 int mean = MEAN_VERSION2;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 BAIL_IF_MACRO(shn_version == -1, NULL, 0);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 if (shn_version < 2) /* downgrade? */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 mean = MEAN_VERSION0;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
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 SNDDBG(("SHN: Accepting data stream.\n"));
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 set up sample->actual;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 sample->flags = SOUND_SAMPLEFLAG_NONE;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 return(1); /* we'll handle this data. */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 } /* SHN_open */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
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 static void SHN_close(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 clean up anything you put into internal->decoder_private;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 } /* SHN_close */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180
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 static Uint32 SHN_read(Sound_Sample *sample)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 {
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 Uint32 retval;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186
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 * 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
189 * directly into the internal buffer...
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 retval = SDL_RWread(internal->rw, internal->buffer,
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 1, internal->buffer_size);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 (or whatever. Do some decoding here...)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 /* Make sure the read went smoothly... */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 if (retval == 0)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 sample->flags |= SOUND_SAMPLEFLAG_EOF;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 else if (retval == -1)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 /* (next call this EAGAIN may turn into an EOF or error.) */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 else if (retval < internal->buffer_size)
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 (or whatever. retval == number of bytes you put in internal->buffer).
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 return(retval);
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 } /* SHN_read */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 #endif /* defined SOUND_SUPPORTS_SHN */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 /* end of shn.c ... */
155ab2a427ca Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215