comparison decoders/modplug.c @ 376:51883cd1193e

WinCE (PocketPC) stuff from Tyler, ModPlug settings maintanance by me.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 02 Jul 2002 03:57:48 +0000
parents f72fd79d6e76
children fb519e6028e3
comparison
equal deleted inserted replaced
375:6095d0a52a20 376:51883cd1193e
38 #ifdef SOUND_SUPPORTS_MODPLUG 38 #ifdef SOUND_SUPPORTS_MODPLUG
39 39
40 #include <stdio.h> 40 #include <stdio.h>
41 #include <stdlib.h> 41 #include <stdlib.h>
42 #include <string.h> 42 #include <string.h>
43 #include <assert.h>
44 43
45 #include "SDL_sound.h" 44 #include "SDL_sound.h"
46 45
47 #define __SDL_SOUND_INTERNAL__ 46 #define __SDL_SOUND_INTERNAL__
48 #include "SDL_sound_internal.h" 47 #include "SDL_sound_internal.h"
107 MODPLUG_rewind, /* rewind() method */ 106 MODPLUG_rewind, /* rewind() method */
108 MODPLUG_seek /* seek() method */ 107 MODPLUG_seek /* seek() method */
109 }; 108 };
110 109
111 110
111 static ModPlug_Settings settings;
112 static Sound_AudioInfo current_audioinfo;
113 static unsigned int total_mods_decoding = 0;
114
112 static int MODPLUG_init(void) 115 static int MODPLUG_init(void)
113 { 116 {
114 ModPlug_Settings settings; 117 /*
115 118 * The settings will require some experimenting. I've borrowed some
116 /* The settings will require some experimenting. I've borrowed some 119 * of them from the XMMS ModPlug plugin.
117 * of them from the XMMS ModPlug plugin. 120 */
118 */ 121 settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING;
119 settings.mFlags = 122
120 MODPLUG_ENABLE_OVERSAMPLING 123 #ifndef _WIN32_WCE
121 | MODPLUG_ENABLE_NOISE_REDUCTION 124 settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION |
122 | MODPLUG_ENABLE_REVERB 125 MODPLUG_ENABLE_REVERB |
123 | MODPLUG_ENABLE_MEGABASS 126 MODPLUG_ENABLE_MEGABASS |
124 | MODPLUG_ENABLE_SURROUND; 127 MODPLUG_ENABLE_SURROUND;
125 settings.mChannels = 2; 128
126 settings.mBits = 16;
127 settings.mFrequency = 44100;
128 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
129 settings.mReverbDepth = 30; 129 settings.mReverbDepth = 30;
130 settings.mReverbDelay = 100; 130 settings.mReverbDelay = 100;
131 settings.mBassAmount = 40; 131 settings.mBassAmount = 40;
132 settings.mBassRange = 30; 132 settings.mBassRange = 30;
133 settings.mSurroundDepth = 20; 133 settings.mSurroundDepth = 20;
134 settings.mSurroundDelay = 20; 134 settings.mSurroundDelay = 20;
135 #endif
136
137 settings.mChannels = 2;
138 settings.mBits = 16;
139 settings.mFrequency = 44100;
140 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
135 settings.mLoopCount = 0; 141 settings.mLoopCount = 0;
142
143 current_audioinfo.channels = 2;
144 current_audioinfo.rate = 44100;
145 current_audioinfo.format = AUDIO_S16SYS;
146 total_mods_decoding = 0;
136 147
137 ModPlug_SetSettings(&settings); 148 ModPlug_SetSettings(&settings);
138 return(1); /* success. */ 149 return(1); /* success. */
139 } /* MODPLUG_init */ 150 } /* MODPLUG_init */
140 151
141 152
142 static void MODPLUG_quit(void) 153 static void MODPLUG_quit(void)
143 { 154 {
155 assert(total_mods_decoding == 0);
144 /* it's a no-op. */ 156 /* it's a no-op. */
145 } /* MODPLUG_quit */ 157 } /* MODPLUG_quit */
146 158
147 159
148 /* 160 /*
179 SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext)); 191 SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext));
180 Sound_SetError("MODPLUG: Not a module file."); 192 Sound_SetError("MODPLUG: Not a module file.");
181 return(0); 193 return(0);
182 } /* if */ 194 } /* if */
183 195
184 /* ModPlug needs the entire stream in one big chunk. I don't like it, 196 /*
185 * but I don't think there's any way around it. 197 * ModPlug needs the entire stream in one big chunk. I don't like it,
198 * but I don't think there's any way around it.
186 */ 199 */
187 data = (Uint8 *) malloc(CHUNK_SIZE); 200 data = (Uint8 *) malloc(CHUNK_SIZE);
188 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); 201 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
189 size = 0; 202 size = 0;
190 203
197 data = (Uint8 *) realloc(data, size + CHUNK_SIZE); 210 data = (Uint8 *) realloc(data, size + CHUNK_SIZE);
198 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0); 211 BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
199 } /* if */ 212 } /* if */
200 } while (retval > 0); 213 } while (retval > 0);
201 214
202 /* The buffer may be a bit too large, but that doesn't matter. I think 215 /*
203 * it's safe to free it as soon as ModPlug_Load() is finished anyway. 216 * It's only safe to change these settings when there're
217 * no other mods being decoded...
218 */
219 if (total_mods_decoding > 0) /* !!! FIXME: Should we mutex this? */
220 {
221 /* other mods decoding: use the same settings they are. */
222 memcpy(&sample->actual, &current_audioinfo, sizeof (Sound_AudioInfo));
223 } /* if */
224 else
225 {
226 /* no other mods decoding: define the new ModPlug output settings. */
227 memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
228 if (sample->actual.rate == 0)
229 sample->actual.rate = 44100;
230 if (sample->actual.channels == 0)
231 sample->actual.channels = 2;
232 if (sample->actual.format == 0)
233 sample->actual.format = AUDIO_S16SYS;
234
235 memcpy(&current_audioinfo, &sample->actual, sizeof (Sound_AudioInfo));
236 settings.mChannels=sample->actual.channels;
237 settings.mFrequency=sample->actual.rate;
238 settings.mBits = sample->actual.format & 0xFF;
239 ModPlug_SetSettings(&settings);
240 } /* else */
241
242 /*
243 * The buffer may be a bit too large, but that doesn't matter. I think
244 * it's safe to free it as soon as ModPlug_Load() is finished anyway.
204 */ 245 */
205 module = ModPlug_Load((void *) data, size); 246 module = ModPlug_Load((void *) data, size);
206 free(data); 247 free(data);
207 BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0); 248 BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0);
208 249
209 SNDDBG(("MODPLUG: [%d ms] %s\n", 250 SNDDBG(("MODPLUG: [%d ms] %s\n",
210 ModPlug_GetLength(module), ModPlug_GetName(module))); 251 ModPlug_GetLength(module), ModPlug_GetName(module)));
211 252
212 sample->actual.channels = 2;
213 sample->actual.rate = 44100;
214 sample->actual.format = AUDIO_S16SYS;
215
216 internal->decoder_private = (void *) module; 253 internal->decoder_private = (void *) module;
217 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; 254 sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
255
256 total_mods_decoding++; /* !!! FIXME: Should we mutex this? */
218 257
219 SNDDBG(("MODPLUG: Accepting data stream\n")); 258 SNDDBG(("MODPLUG: Accepting data stream\n"));
220 return(1); /* we'll handle this data. */ 259 return(1); /* we'll handle this data. */
221 } /* MODPLUG_open */ 260 } /* MODPLUG_open */
222 261
223 262
224 static void MODPLUG_close(Sound_Sample *sample) 263 static void MODPLUG_close(Sound_Sample *sample)
225 { 264 {
226 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; 265 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
227 ModPlugFile *module = (ModPlugFile *) internal->decoder_private; 266 ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
267 total_mods_decoding--;
228 268
229 ModPlug_Unload(module); 269 ModPlug_Unload(module);
230 } /* MODPLUG_close */ 270 } /* MODPLUG_close */
231 271
232 272