Mercurial > SDL_sound_CoreAudio
annotate decoders/modplug.c @ 387:fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 05 Jul 2002 23:11:51 +0000 |
parents | 51883cd1193e |
children | 53ce18591f5d |
rev | line source |
---|---|
208 | 1 /* |
2 * SDL_sound -- An abstract sound format decoding API. | |
3 * Copyright (C) 2001 Ryan C. Gordon. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 | |
20 /* | |
21 * Module player for SDL_sound. This driver handles anything that ModPlug does. | |
22 * | |
349
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
23 * ModPlug can be found at http://sourceforge.net/projects/modplug-xmms |
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
24 * |
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
25 * An unofficial version of modplug with all C++ dependencies removed is also |
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
26 * available: http://freecraft.net/snapshots/ |
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
27 * (Look for something like "libmodplug-johns-*.tar.gz") |
f72fd79d6e76
Added URLs for official and unofficial versions of ModPlug.
Ryan C. Gordon <icculus@icculus.org>
parents:
312
diff
changeset
|
28 * |
208 | 29 * Please see the file COPYING in the source's root directory. |
30 * | |
31 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE) | |
32 */ | |
33 | |
34 #if HAVE_CONFIG_H | |
35 # include <config.h> | |
36 #endif | |
37 | |
38 #ifdef SOUND_SUPPORTS_MODPLUG | |
39 | |
40 #include <stdio.h> | |
41 #include <stdlib.h> | |
42 #include <string.h> | |
43 | |
44 #include "SDL_sound.h" | |
45 | |
46 #define __SDL_SOUND_INTERNAL__ | |
47 #include "SDL_sound_internal.h" | |
48 | |
49 #include "modplug.h" | |
50 | |
51 | |
52 static int MODPLUG_init(void); | |
53 static void MODPLUG_quit(void); | |
54 static int MODPLUG_open(Sound_Sample *sample, const char *ext); | |
55 static void MODPLUG_close(Sound_Sample *sample); | |
56 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
|
57 static int MODPLUG_rewind(Sound_Sample *sample); |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
58 static int MODPLUG_seek(Sound_Sample *sample, Uint32 ms); |
208 | 59 |
60 static const char *extensions_modplug[] = | |
61 { | |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
62 /* 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
|
63 * 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
|
64 */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
65 "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
|
66 "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
|
67 "AMS", /* AMS module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
68 "DBM", /* DigiBooster Pro Module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
69 "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
|
70 "DSM", /* DSIK Internal Format module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
71 "FAR", /* Farandole module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
72 "IT", /* Impulse Tracker IT file */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
73 "MDL", /* DigiTracker module */ |
208 | 74 #if 0 |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
75 "J2B", /* Not implemented? What is it anyway? */ |
208 | 76 #endif |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
77 "MED", /* OctaMed MED file */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
78 "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
|
79 "MT2", /* MadTracker 2.0 */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
80 "MTM", /* MTM file */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
81 "OKT", /* Oktalyzer module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
82 "PTM", /* PTM PolyTracker module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
83 "PSM", /* PSM module */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
84 "S3M", /* ScreamTracker file */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
85 "STM", /* ST 2.xx */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
86 "ULT", |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
87 "UMX", |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
88 "XM", /* FastTracker II */ |
208 | 89 NULL |
90 }; | |
91 | |
92 const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG = | |
93 { | |
94 { | |
95 extensions_modplug, | |
96 "Play modules through ModPlug", | |
97 "Torbjörn Andersson <d91tan@Update.UU.SE>", | |
98 "http://modplug-xmms.sourceforge.net/" | |
99 }, | |
100 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
101 MODPLUG_init, /* init() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
102 MODPLUG_quit, /* quit() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
103 MODPLUG_open, /* open() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
104 MODPLUG_close, /* close() method */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
105 MODPLUG_read, /* read() method */ |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
106 MODPLUG_rewind, /* rewind() method */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
107 MODPLUG_seek /* seek() method */ |
208 | 108 }; |
109 | |
110 | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
111 static ModPlug_Settings settings; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
112 static Sound_AudioInfo current_audioinfo; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
113 static unsigned int total_mods_decoding = 0; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
114 |
208 | 115 static int MODPLUG_init(void) |
116 { | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
117 /* |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
118 * The settings will require some experimenting. I've borrowed some |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
119 * of them from the XMMS ModPlug plugin. |
208 | 120 */ |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
121 settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
122 |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
123 #ifndef _WIN32_WCE |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
124 settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION | |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
125 MODPLUG_ENABLE_REVERB | |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
126 MODPLUG_ENABLE_MEGABASS | |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
127 MODPLUG_ENABLE_SURROUND; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
128 |
208 | 129 settings.mReverbDepth = 30; |
130 settings.mReverbDelay = 100; | |
131 settings.mBassAmount = 40; | |
132 settings.mBassRange = 30; | |
133 settings.mSurroundDepth = 20; | |
134 settings.mSurroundDelay = 20; | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
135 #endif |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
136 |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
137 settings.mChannels = 2; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
138 settings.mBits = 16; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
139 settings.mFrequency = 44100; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
140 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; |
208 | 141 settings.mLoopCount = 0; |
142 | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
143 current_audioinfo.channels = 2; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
144 current_audioinfo.rate = 44100; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
145 current_audioinfo.format = AUDIO_S16SYS; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
146 total_mods_decoding = 0; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
147 |
208 | 148 ModPlug_SetSettings(&settings); |
149 return(1); /* success. */ | |
150 } /* MODPLUG_init */ | |
151 | |
152 | |
153 static void MODPLUG_quit(void) | |
154 { | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
155 assert(total_mods_decoding == 0); |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
156 /* it's a no-op. */ |
208 | 157 } /* MODPLUG_quit */ |
158 | |
159 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
160 /* |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
161 * Most MOD files I've seen have tended to be a few hundred KB, even if some |
208 | 162 * of them were much smaller than that. |
163 */ | |
164 #define CHUNK_SIZE 65536 | |
165 | |
166 static int MODPLUG_open(Sound_Sample *sample, const char *ext) | |
167 { | |
168 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
169 ModPlugFile *module; | |
170 Uint8 *data; | |
171 size_t size; | |
172 Uint32 retval; | |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
173 int has_extension = 0; |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
174 int i; |
208 | 175 |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
176 /* |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
177 * 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
|
178 * 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
|
179 */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
180 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
|
181 { |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
182 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
|
183 { |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
184 has_extension = 1; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
185 break; |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
186 } /* if */ |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
187 } /* for */ |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
188 |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
189 if (!has_extension) |
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
190 { |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
191 SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext)); |
387
fb519e6028e3
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
Ryan C. Gordon <icculus@icculus.org>
parents:
376
diff
changeset
|
192 BAIL_MACRO("MODPLUG: Not a module file.", 0); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
193 } /* if */ |
211
b35c04e4691e
Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents:
208
diff
changeset
|
194 |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
195 /* |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
196 * ModPlug needs the entire stream in one big chunk. I don't like it, |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
197 * but I don't think there's any way around it. |
208 | 198 */ |
199 data = (Uint8 *) malloc(CHUNK_SIZE); | |
200 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); | |
201 size = 0; | |
202 | |
203 do | |
204 { | |
205 retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE); | |
206 size += retval; | |
207 if (retval == CHUNK_SIZE) | |
208 { | |
209 data = (Uint8 *) realloc(data, size + CHUNK_SIZE); | |
210 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); | |
211 } /* if */ | |
212 } while (retval > 0); | |
213 | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
214 /* |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
215 * It's only safe to change these settings when there're |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
216 * no other mods being decoded... |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
217 */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
218 if (total_mods_decoding > 0) /* !!! FIXME: Should we mutex this? */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
219 { |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
220 /* other mods decoding: use the same settings they are. */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
221 memcpy(&sample->actual, ¤t_audioinfo, sizeof (Sound_AudioInfo)); |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
222 } /* if */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
223 else |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
224 { |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
225 /* no other mods decoding: define the new ModPlug output settings. */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
226 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo)); |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
227 if (sample->actual.rate == 0) |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
228 sample->actual.rate = 44100; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
229 if (sample->actual.channels == 0) |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
230 sample->actual.channels = 2; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
231 if (sample->actual.format == 0) |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
232 sample->actual.format = AUDIO_S16SYS; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
233 |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
234 memcpy(¤t_audioinfo, &sample->actual, sizeof (Sound_AudioInfo)); |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
235 settings.mChannels=sample->actual.channels; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
236 settings.mFrequency=sample->actual.rate; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
237 settings.mBits = sample->actual.format & 0xFF; |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
238 ModPlug_SetSettings(&settings); |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
239 } /* else */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
240 |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
241 /* |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
242 * The buffer may be a bit too large, but that doesn't matter. I think |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
243 * it's safe to free it as soon as ModPlug_Load() is finished anyway. |
208 | 244 */ |
245 module = ModPlug_Load((void *) data, size); | |
246 free(data); | |
247 BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0); | |
248 | |
249 SNDDBG(("MODPLUG: [%d ms] %s\n", | |
250 ModPlug_GetLength(module), ModPlug_GetName(module))); | |
251 | |
252 internal->decoder_private = (void *) module; | |
312 | 253 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
208 | 254 |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
255 total_mods_decoding++; /* !!! FIXME: Should we mutex this? */ |
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
256 |
208 | 257 SNDDBG(("MODPLUG: Accepting data stream\n")); |
258 return(1); /* we'll handle this data. */ | |
259 } /* MODPLUG_open */ | |
260 | |
261 | |
262 static void MODPLUG_close(Sound_Sample *sample) | |
263 { | |
264 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
265 ModPlugFile *module = (ModPlugFile *) internal->decoder_private; | |
376
51883cd1193e
WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
349
diff
changeset
|
266 total_mods_decoding--; |
208 | 267 |
268 ModPlug_Unload(module); | |
269 } /* MODPLUG_close */ | |
270 | |
271 | |
272 static Uint32 MODPLUG_read(Sound_Sample *sample) | |
273 { | |
274 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | |
275 ModPlugFile *module = (ModPlugFile *) internal->decoder_private; | |
276 int retval; | |
277 | |
278 retval = ModPlug_Read(module, internal->buffer, internal->buffer_size); | |
279 if (retval == 0) | |
280 sample->flags |= SOUND_SAMPLEFLAG_EOF; | |
281 return(retval); | |
282 } /* MODPLUG_read */ | |
283 | |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
284 |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
285 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
|
286 { |
231
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
287 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
288 ModPlugFile *module = (ModPlugFile *) internal->decoder_private; |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
289 |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
290 ModPlug_Seek(module, 0); |
d3dc34315ac7
Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents:
221
diff
changeset
|
291 return(1); |
221
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
292 } /* MODPLUG_rewind */ |
c9772a9f5271
Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
211
diff
changeset
|
293 |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
294 |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
295 static int MODPLUG_seek(Sound_Sample *sample, Uint32 ms) |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
296 { |
312 | 297 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
298 ModPlugFile *module = (ModPlugFile *) internal->decoder_private; | |
299 | |
300 /* Assume that this will work. */ | |
301 ModPlug_Seek(module, ms); | |
302 return(1); | |
306
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
303 } /* MODPLUG_seek */ |
c97be6e1bd27
Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents:
231
diff
changeset
|
304 |
208 | 305 #endif /* SOUND_SUPPORTS_MODPLUG */ |
306 | |
307 | |
308 /* end of modplug.c ... */ |