annotate decoders/modplug.c @ 591:8faf61a640f0 tip

Resynced fixes for unit conversion bugs in the Ogg Tremor decoder from SoundDecoder/ALmixer. Ogg Vorbis uses seconds and we multiply by 1000 to convert to milliseconds. But Ogg Tremor already uses milliseconds but I was still multiplying by 1000.
author Eric Wing <ewing . public |-at-| gmail . com>
date Thu, 25 Oct 2012 16:34:18 -0700
parents fa857159dbdf
children
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 *
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 *
552
2e8907ff98e9 Replaced references to COPYING with references to LICENSE.txt ...
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
29 * Please see the file LICENSE.txt in the source's root directory.
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 *
536
8a814bbbedfa Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
Ryan C. Gordon <icculus@icculus.org>
parents: 496
diff changeset
31 * This file written by Torbjörn Andersson (d91tan@Update.UU.SE)
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 */
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 #if HAVE_CONFIG_H
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 # include <config.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #endif
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #ifdef SOUND_SUPPORTS_MODPLUG
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #include <stdio.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include <stdlib.h>
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include <string.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 "SDL_sound.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 #define __SDL_SOUND_INTERNAL__
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #include "SDL_sound_internal.h"
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
496
67d785044411 Forward port from stable branch: fix modplug header detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
49 #if SOUND_MODPLUG_IN_OWN_PATH
67d785044411 Forward port from stable branch: fix modplug header detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
50 #include "libmodplug/modplug.h"
67d785044411 Forward port from stable branch: fix modplug header detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
51 #else
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #include "modplug.h"
496
67d785044411 Forward port from stable branch: fix modplug header detection.
Ryan C. Gordon <icculus@icculus.org>
parents: 477
diff changeset
53 #endif
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 static int MODPLUG_init(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 static void MODPLUG_quit(void);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static int MODPLUG_open(Sound_Sample *sample, const char *ext);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static void MODPLUG_close(Sound_Sample *sample);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 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
60 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
61 static int MODPLUG_seek(Sound_Sample *sample, Uint32 ms);
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 static const char *extensions_modplug[] =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 {
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
65 /* 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
66 * 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
67 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
68 "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
69 "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
70 "AMS", /* AMS module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
71 "DBM", /* DigiBooster Pro Module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
72 "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
73 "DSM", /* DSIK Internal Format module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
74 "FAR", /* Farandole module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
75 "IT", /* Impulse Tracker IT file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
76 "MDL", /* DigiTracker module */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 #if 0
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
78 "J2B", /* Not implemented? What is it anyway? */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 #endif
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
80 "MED", /* OctaMed MED file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
81 "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
82 "MT2", /* MadTracker 2.0 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
83 "MTM", /* MTM file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
84 "OKT", /* Oktalyzer module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
85 "PTM", /* PTM PolyTracker module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
86 "PSM", /* PSM module */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
87 "S3M", /* ScreamTracker file */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
88 "STM", /* ST 2.xx */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
89 "ULT",
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
90 "UMX",
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
91 "XM", /* FastTracker II */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 NULL
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
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG =
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 extensions_modplug,
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 "Play modules through ModPlug",
536
8a814bbbedfa Merged r544:545 from branches/stable-1.0: converted to UTF-8 encoding.
Ryan C. Gordon <icculus@icculus.org>
parents: 496
diff changeset
100 "Torbjörn Andersson <d91tan@Update.UU.SE>",
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 "http://modplug-xmms.sourceforge.net/"
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
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
104 MODPLUG_init, /* init() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
105 MODPLUG_quit, /* quit() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
106 MODPLUG_open, /* open() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
107 MODPLUG_close, /* close() method */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
108 MODPLUG_read, /* read() method */
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
109 MODPLUG_rewind, /* rewind() method */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
110 MODPLUG_seek /* seek() method */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 };
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
114 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
115 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
116 static unsigned int total_mods_decoding = 0;
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
117 static SDL_mutex *modplug_mutex = NULL;
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
118
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 static int MODPLUG_init(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 {
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
121 assert(modplug_mutex == NULL);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
122
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
123 /*
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
124 * 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
125 * of them from the XMMS ModPlug plugin.
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 */
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
127 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
128
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
129 #ifndef _WIN32_WCE
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
130 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
131 MODPLUG_ENABLE_MEGABASS |
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
132 MODPLUG_ENABLE_SURROUND;
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
133
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 settings.mReverbDepth = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 settings.mReverbDelay = 100;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 settings.mBassAmount = 40;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 settings.mBassRange = 30;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 settings.mSurroundDepth = 20;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 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
140 #endif
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
141
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
142 settings.mChannels = 2;
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
143 settings.mBits = 16;
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
144 settings.mFrequency = 44100;
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
145 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 settings.mLoopCount = 0;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
148 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
149 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
150 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
151 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
152
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
153 modplug_mutex = SDL_CreateMutex();
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
154
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 ModPlug_SetSettings(&settings);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 return(1); /* success. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 } /* MODPLUG_init */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 static void MODPLUG_quit(void)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 {
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
162 assert(total_mods_decoding == 0);
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
163
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
164 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
165 {
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
166 SDL_DestroyMutex(modplug_mutex);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
167 modplug_mutex = NULL;
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
168 } /* if */
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 } /* MODPLUG_quit */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
172 /*
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
173 * 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
174 * of them were much smaller than that.
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 #define CHUNK_SIZE 65536
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 static int MODPLUG_open(Sound_Sample *sample, const char *ext)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 ModPlugFile *module;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 Uint8 *data;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 size_t size;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 Uint32 retval;
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
185 int has_extension = 0;
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
186 int i;
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
188 /*
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
189 * 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
190 * 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
191 */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
192 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
193 {
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
194 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
195 {
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
196 has_extension = 1;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
197 break;
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
198 } /* if */
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
199 } /* for */
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
200
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
201 if (!has_extension)
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
202 {
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
203 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
204 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
205 } /* if */
211
b35c04e4691e Patched to select streams to handle more carefully.
Ryan C. Gordon <icculus@icculus.org>
parents: 208
diff changeset
206
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
207 /*
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
208 * 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
209 * but I don't think there's any way around it.
208
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 data = (Uint8 *) malloc(CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 size = 0;
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 do
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 size += retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 if (retval == CHUNK_SIZE)
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 data = (Uint8 *) realloc(data, size + CHUNK_SIZE);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 } /* if */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 } while (retval > 0);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
226 /*
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
227 * 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
228 * 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
229 */
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
230 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
231 SDL_LockMutex(modplug_mutex);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
232
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
233 if (total_mods_decoding > 0)
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
234 {
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
235 /* 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
236 memcpy(&sample->actual, &current_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
237 } /* if */
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
238 else
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
239 {
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
240 /* 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
249 memcpy(&current_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
250 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
251 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
252 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
253 ModPlug_SetSettings(&settings);
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
254 } /* else */
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
255
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
256 /*
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
257 * 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
258 * it's safe to free it as soon as ModPlug_Load() is finished anyway.
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 module = ModPlug_Load((void *) data, size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 free(data);
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
262 if (module == NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
263 {
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
264 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
265 SDL_UnlockMutex(modplug_mutex);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
266
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
267 BAIL_MACRO("MODPLUG: Not a module file.", 0);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
268 } /* if */
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
269
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
270 total_mods_decoding++;
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
271
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
272 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
273 SDL_UnlockMutex(modplug_mutex);
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274
477
3e705c9180e5 Fixed binary compatibility, added Sound_GetDuration().
Ryan C. Gordon <icculus@icculus.org>
parents: 474
diff changeset
275 internal->total_time = ModPlug_GetLength(module);
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 SNDDBG(("MODPLUG: [%d ms] %s\n",
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 ModPlug_GetLength(module), ModPlug_GetName(module)));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 internal->decoder_private = (void *) module;
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
280 sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 SNDDBG(("MODPLUG: Accepting data stream\n"));
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 return(1); /* we'll handle this data. */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 } /* MODPLUG_open */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 static void MODPLUG_close(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
291
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
292 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
293 SDL_LockMutex(modplug_mutex);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
294
376
51883cd1193e WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
Ryan C. Gordon <icculus@icculus.org>
parents: 349
diff changeset
295 total_mods_decoding--;
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296
395
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
297 if (modplug_mutex != NULL)
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
298 SDL_UnlockMutex(modplug_mutex);
53ce18591f5d Mutex'd a potential race condition.
Ryan C. Gordon <icculus@icculus.org>
parents: 387
diff changeset
299
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 ModPlug_Unload(module);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 } /* MODPLUG_close */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 static Uint32 MODPLUG_read(Sound_Sample *sample)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 {
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 int retval;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 retval = ModPlug_Read(module, internal->buffer, internal->buffer_size);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 if (retval == 0)
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 sample->flags |= SOUND_SAMPLEFLAG_EOF;
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 return(retval);
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 } /* MODPLUG_read */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
316
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
317 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
318 {
231
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
319 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
320 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
321
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
322 ModPlug_Seek(module, 0);
d3dc34315ac7 Rewind method implemented by Torbj�rn.
Ryan C. Gordon <icculus@icculus.org>
parents: 221
diff changeset
323 return(1);
221
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
324 } /* MODPLUG_rewind */
c9772a9f5271 Initial implementation or stubs for rewind method. Other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
325
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
326
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
327 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
328 {
312
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
329 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
330 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
331
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
332 /* Assume that this will work. */
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
333 ModPlug_Seek(module, ms);
498240aa76f1 Seek implementations.
Ryan C. Gordon <icculus@icculus.org>
parents: 306
diff changeset
334 return(1);
306
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
335 } /* MODPLUG_seek */
c97be6e1bd27 Added framework for Sound_Seek() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 231
diff changeset
336
208
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 #endif /* SOUND_SUPPORTS_MODPLUG */
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339
32376317eedb Initial adds.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 /* end of modplug.c ... */