annotate decoders/modplug.c @ 276:d7d55903124c

Changed --enable-vorbis to --enable-ogg, made other format tweaks.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 14 Mar 2002 16:16:53 +0000
parents d3dc34315ac7
children c97be6e1bd27
rev   line source
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Module player for SDL_sound. This driver handles anything that ModPlug does.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * Please see the file COPYING in the source's root directory.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 *
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #if HAVE_CONFIG_H
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 # include <config.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #endif
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #ifdef SOUND_SUPPORTS_MODPLUG
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include <stdio.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include <stdlib.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <string.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <assert.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "SDL_sound.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #define __SDL_SOUND_INTERNAL__
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include "SDL_sound_internal.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include "modplug.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 static int MODPLUG_init(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 static void MODPLUG_quit(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 static int MODPLUG_open(Sound_Sample *sample, const char *ext);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 static void MODPLUG_close(Sound_Sample *sample);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 static Uint32 MODPLUG_read(Sound_Sample *sample);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
52 static int MODPLUG_rewind(Sound_Sample *sample);
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 static const char *extensions_modplug[] =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 {
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
56 /* The XMMS plugin is apparently able to load compressed modules as
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
57 * well, but libmodplug does not handle this.
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
58 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
59 "669", /* Composer 669 / UNIS 669 module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
60 "AMF", /* ASYLUM Music Format / Advanced Music Format(DSM) */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
61 "AMS", /* AMS module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
62 "DBM", /* DigiBooster Pro Module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
63 "DMF", /* DMF DELUSION DIGITAL MUSIC FILEFORMAT (X-Tracker) */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
64 "DSM", /* DSIK Internal Format module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
65 "FAR", /* Farandole module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
66 "IT", /* Impulse Tracker IT file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
67 "MDL", /* DigiTracker module */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 #if 0
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
69 "J2B", /* Not implemented? What is it anyway? */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 #endif
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
71 "MED", /* OctaMed MED file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
72 "MOD", /* ProTracker / NoiseTracker MOD/NST file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
73 "MT2", /* MadTracker 2.0 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
74 "MTM", /* MTM file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
75 "OKT", /* Oktalyzer module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
76 "PTM", /* PTM PolyTracker module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
77 "PSM", /* PSM module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
78 "S3M", /* ScreamTracker file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
79 "STM", /* ST 2.xx */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
80 "ULT",
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
81 "UMX",
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
82 "XM", /* FastTracker II */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 NULL
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 };
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 extensions_modplug,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 "Play modules through ModPlug",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 "Torbjörn Andersson <d91tan@Update.UU.SE>",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 "http://modplug-xmms.sourceforge.net/"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 },
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
95 MODPLUG_init, /* init() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
96 MODPLUG_quit, /* quit() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
97 MODPLUG_open, /* open() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
98 MODPLUG_close, /* close() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
99 MODPLUG_read, /* read() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
100 MODPLUG_rewind /* rewind() method */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 };
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 static int MODPLUG_init(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 ModPlug_Settings settings;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 /* The settings will require some experimenting. I've borrowed some
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 * of them from the XMMS ModPlug plugin.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 settings.mFlags =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 MODPLUG_ENABLE_OVERSAMPLING
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 | MODPLUG_ENABLE_NOISE_REDUCTION
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 | MODPLUG_ENABLE_REVERB
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 | MODPLUG_ENABLE_MEGABASS
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 | MODPLUG_ENABLE_SURROUND;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 settings.mChannels = 2;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 settings.mBits = 16;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 settings.mFrequency = 44100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 settings.mReverbDepth = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 settings.mReverbDelay = 100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 settings.mBassAmount = 40;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 settings.mBassRange = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 settings.mSurroundDepth = 20;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 settings.mSurroundDelay = 20;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 settings.mLoopCount = 0;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 ModPlug_SetSettings(&settings);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 return(1); /* success. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 } /* MODPLUG_init */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 static void MODPLUG_quit(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 {
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
136 /* it's a no-op. */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 } /* MODPLUG_quit */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
140 /*
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
141 * Most MOD files I've seen have tended to be a few hundred KB, even if some
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 * of them were much smaller than that.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 #define CHUNK_SIZE 65536
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 static int MODPLUG_open(Sound_Sample *sample, const char *ext)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 ModPlugFile *module;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 Uint8 *data;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 size_t size;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 Uint32 retval;
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
153 int has_extension = 0;
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
154 int i;
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
156 /*
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
157 * Apparently ModPlug's loaders are too forgiving. They gladly accept
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
158 * streams that they shouldn't. For now, rely on file extension instead.
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
159 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
160 for (i = 0; extensions_modplug[i] != NULL; i++)
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
161 {
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
162 if (__Sound_strcasecmp(ext, extensions_modplug[i]) == 0)
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
163 {
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
164 has_extension = 1;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
165 break;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
166 } /* if */
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
167 } /* for */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
168
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
169 if (!has_extension)
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
170 {
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
171 SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext));
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
172 Sound_SetError("MODPLUG: Not a module file.");
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
173 return(0);
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
174 } /* if */
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
175
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 /* ModPlug needs the entire stream in one big chunk. I don't like it,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 * but I don't think there's any way around it.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 data = (Uint8 *) malloc(CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 size = 0;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 do
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 size += retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 if (retval == CHUNK_SIZE)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 data = (Uint8 *) realloc(data, size + CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 } /* if */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 } while (retval > 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 /* The buffer may be a bit too large, but that doesn't matter. I think
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 * it's safe to free it as soon as ModPlug_Load() is finished anyway.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 module = ModPlug_Load((void *) data, size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 free(data);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 SNDDBG(("MODPLUG: [%d ms] %s\n",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 ModPlug_GetLength(module), ModPlug_GetName(module)));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 sample->actual.channels = 2;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 sample->actual.rate = 44100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 sample->actual.format = AUDIO_S16SYS;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 internal->decoder_private = (void *) module;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 sample->flags = SOUND_SAMPLEFLAG_NONE;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 SNDDBG(("MODPLUG: Accepting data stream\n"));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 return(1); /* we'll handle this data. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 } /* MODPLUG_open */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 static void MODPLUG_close(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 ModPlug_Unload(module);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 } /* MODPLUG_close */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 static Uint32 MODPLUG_read(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 int retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 retval = ModPlug_Read(module, internal->buffer, internal->buffer_size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 if (retval == 0)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 sample->flags |= SOUND_SAMPLEFLAG_EOF;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 return(retval);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 } /* MODPLUG_read */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
237
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
238 static int MODPLUG_rewind(Sound_Sample *sample)
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
239 {
231
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
240 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
241 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
242
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
243 ModPlug_Seek(module, 0);
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
244 return(1);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
245 } /* MODPLUG_rewind */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
246
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 #endif /* SOUND_SUPPORTS_MODPLUG */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 /* end of modplug.c ... */