1 /****************************************************************************
3 * ____ ___ ____ __ ______ ___ ____ ____/ / *
4 * / __ `__ \/ __ `/ |/ / __ `__ \/ __ \/ __ / *
5 * / / / / / / /_/ /> </ / / / / / /_/ / /_/ / *
6 * /_/ /_/ /_/\__,_/_/|_/_/ /_/ /_/\____/\__,_/ *
10 * Copyright (c) 2008, Mukunda Johnson (mukunda@maxmod.org) *
12 * Permission to use, copy, modify, and/or distribute this software for any *
13 * purpose with or without fee is hereby granted, provided that the above *
14 * copyright notice and this permission notice appear in all copies. *
16 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
17 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
18 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
19 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *
22 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
23 ****************************************************************************/
26 #error "maxmod7.h is for ARM7!"
29 //----------------------------------------------------------------
31 //----------------------------------------------------------------
37 //----------------------------------------------------------------
41 //----------------------------------------------------------------
43 /*****************************************************************
44 * mmInstall( channel )
48 * channel : IPC/FIFO channel to use, usually 7.
49 *****************************************************************/
51 void mmInstall( int fifo_channel );
53 /*****************************************************************
54 * mmLockChannels( mm_word bitmask )
56 * Lock audio channels from being used by Maxmod.
58 * bitmask : Bitmask of which channels should be locked.
59 * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...)
60 *****************************************************************/
62 void mmLockChannels( mm_word bitmask );
64 /*****************************************************************
65 * mmUnlockChannels( mm_word bitmask )
67 * Unlock audio channels so Maxmod can use them.
69 * bitmask : Bitmask of which channels should be unlocked.
70 * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...)
71 *****************************************************************/
73 void mmUnlockChannels( mm_word bitmask );
75 /*****************************************************************
78 * Returns whether or not the system is ready for playback.
79 *****************************************************************/
81 mm_bool mmIsInitialized( void );
83 /*****************************************************************
84 * mmSelectMode( mm_mode_enum mode )
89 * MM_MODE_A : Hardware Mixing
90 * MM_MODE_B : Interpolated Mixing
91 * MM_MODE_C : Extended Mixing
92 *****************************************************************/
94 void mmSelectMode( mm_mode_enum mode );
96 /*****************************************************************
99 * Work routine (called automatically)
100 *****************************************************************/
102 void mmFrame( void );
104 // note about using sleep functions:
105 // do not use during an interrupt!! it's not safe
106 // and do not exit sleep unless it is already sleeping.
110 /*****************************************************************
114 *****************************************************************/
118 /*****************************************************************
119 * mmStart( mm_word module_ID, mm_pmode mode )
121 * Start module playback
123 * module_ID : Index of module to play. (defined in soundbank header)
124 * mode : Mode of playback: MM_PLAY_ONCE or MM_PLAY_LOOP
125 *****************************************************************/
127 void mmStart( mm_word module_ID, mm_pmode mode );
129 /*****************************************************************
132 * Pause module playback.
133 *****************************************************************/
135 void mmPause( void );
137 /*****************************************************************
140 * Resume module playback
141 *****************************************************************/
143 void mmResume( void );
145 /*****************************************************************
148 * Stop module playback. Start again (from the beginning)
150 *****************************************************************/
154 /*****************************************************************
155 * mmPosition( mm_word position )
157 * Set playback position.
159 * position : New position in module sequence.
160 *****************************************************************/
162 void mmPosition( mm_word position );
164 /*****************************************************************
167 * Returns nonzero if module is playing
168 *****************************************************************/
170 mm_bool mmActive( void );
172 /*****************************************************************
173 * mmJingle( mm_word module_ID )
175 * Play module as jingle. Jingles are limited to 4 channels only.
177 * module_ID : ID of module (defined in soundbank header)
178 *****************************************************************/
180 void mmJingle( mm_word module_ID );
182 /*****************************************************************
185 * Returns nonzero if a jingle is actively playing.
186 *****************************************************************/
188 mm_bool mmActiveSub( void );
190 /*****************************************************************
191 * mmSetModuleVolume( mm_word volume )
192 * mmSetJingleVolume( mm_word volume )
194 * Set volume scaler for music/jingles.
196 * volume : 0->1024 = silent..normal
197 *****************************************************************/
199 void mmSetModuleVolume( mm_word volume );
200 void mmSetJingleVolume( mm_word volume );
202 /*****************************************************************
203 * mmPlayModule( mm_word address, mm_word mode, mm_word layer )
205 * Play direct MAS file
206 *****************************************************************/
208 void mmPlayModule( mm_word address, mm_word mode, mm_word layer );
212 /*****************************************************************
216 *****************************************************************/
220 /*****************************************************************
221 * mmEffect( mm_word sample_ID )
223 * Play a sound effect at its default frequency with full volume
224 * and centered panning. Effect must be loaded first via
227 * sample_ID : Sound effect ID. (defined in soundbank header)
228 *****************************************************************/
230 mm_sfxhand mmEffect( mm_word sample_ID );
232 /*****************************************************************
233 * mmEffectEx( mm_sound_effect* sound )
235 * Play a sound effect with the parameters supplied.
237 * sound : Sound effect attributes.
238 *****************************************************************/
240 mm_sfxhand mmEffectEx( mm_sound_effect* sound );
242 /*****************************************************************
243 * mmEffectVolume( mm_sfxhand handle, mm_word volume )
245 * Set the volume of a sound effect.
247 * handle : Sound effect handle.
249 *****************************************************************/
251 void mmEffectVolume( mm_sfxhand handle, mm_word volume );
253 /*****************************************************************
254 * mmEffectPanning( mm_sfxhand handle, mm_word panning )
256 * Set the panning of a sound effect.
258 * handle : Sound effect handle.
259 * panning : 0->255 = left..right
260 *****************************************************************/
262 void mmEffectPanning( mm_sfxhand handle, mm_byte panning );
264 /*****************************************************************
265 * mmEffectRate( mm_sfxhand handle, mm_word rate )
267 * Set the playback rate of an effect.
269 * handle : Sound effect handle.
271 *****************************************************************/
273 void mmEffectRate( mm_sfxhand handle, mm_word rate );
275 /*****************************************************************
276 * mmEffectScaleRate( mm_sfxhand handle, mm_word factor )
278 * Scale the playback rate of an effect.
280 * handle : Sound effect handle.
281 * factor : 6.10 fixed point factor.
282 *****************************************************************/
284 void mmEffectScaleRate( mm_sfxhand handle, mm_word factor );
286 /*****************************************************************
287 * mmEffectCancel( mm_sfxhand handle )
291 * handle : Sound effect handle.
292 *****************************************************************/
294 void mmEffectCancel( mm_sfxhand handle );
296 /*****************************************************************
297 * mmEffectRelease( mm_sfxhand handle )
299 * Release sound effect (invalidate handle and allow interruption)
301 * handle : Sound effect handle.
302 *****************************************************************/
304 void mmEffectRelease( mm_sfxhand handle );
306 /*****************************************************************
307 * mmSetEffectsVolume( mm_word volume )
309 * Set master volume scale for effect playback.
311 * volume : 0->1024 representing 0%->100% volume
312 *****************************************************************/
314 void mmSetEffectsVolume( mm_word volume );
316 /*****************************************************************
317 * mmEffectCancelAll()
319 * Stop all sound effects
320 *****************************************************************/
322 void mmEffectCancelAll();
326 /*****************************************************************
330 *****************************************************************/
333 /*****************************************************************
334 * mmStreamOpen( mm_stream* stream, mm_addr wavebuffer, mm_addr workbuffer )
338 * stream : Configuration struct
339 * wavebuffer : wave memory, must be aligned
340 * workbuffer : work memory, must be aligned
341 *****************************************************************/
343 void mmStreamOpen( mm_stream* stream, mm_addr wavebuffer, mm_addr workbuffer );
345 /*****************************************************************
348 * Fills the stream with wave data.
349 * This only needs to be called in 'manual' mode. It
350 * is called automatically in 'auto' mode.
351 *****************************************************************/
353 void mmStreamUpdate( void );
355 /*****************************************************************
358 * Close audio stream.
359 *****************************************************************/
361 void mmStreamClose( void );
363 /*****************************************************************
364 * mmStreamGetPosition()
366 * Get number of samples elapsed since the stream was opened.
367 * The 32-bit value will wrap every 36 hours or so (at 32khz)
368 *****************************************************************/
370 mm_word mmStreamGetPosition();
374 /*****************************************************************
378 *****************************************************************/
382 /*****************************************************************
385 * Enable reverb system. (use before configuring!)
386 *****************************************************************/
388 void mmReverbEnable( void );
390 /*****************************************************************
391 * mmReverbConfigure( mm_reverb_cfg* config )
393 * Configure reverb parameters.
394 * config : Configuration data.
395 *****************************************************************/
397 void mmReverbConfigure( mm_reverb_cfg* config );
399 /*****************************************************************
400 * mmReverbStart( mm_reverbch channels )
402 * Start reverb output.
403 *****************************************************************/
405 void mmReverbStart( mm_reverbch channels );
407 /*****************************************************************
408 * mmReverbStop( mm_reverch channels )
410 * Stop reverb output.
411 *****************************************************************/
413 void mmReverbStop( mm_reverbch channels );
415 /*****************************************************************
416 * mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate,
419 * Calculate reverb buffer size based on bit depth, delay
422 * bit_depth : Pass 8 or 16 for 8-bit/16-bit
424 * delay : In milliseconds
426 * Returns size in WORDS.
427 *****************************************************************/
429 static inline mm_word mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate, mm_word delay )
431 if( bit_depth == 16 )
433 return ((((sampling_rate * delay * 2) / 1000) + 3) & (~3)) / 4;
437 return ((((sampling_rate * delay) / 1000) + 3) & (~3)) / 4;
441 /*****************************************************************
444 * Disable reverb system.
445 *****************************************************************/
447 void mmReverbDisable( void );
451 //----------------------------------------------------------------
455 //----------------------------------------------------------------
457 /*****************************************************************
459 *****************************************************************/
461 //----------------------------------------------------------------
462 // This happens when Maxmod reads an SFx (or mod/xm EFx) effect
463 // from a module. It will pass 'x' in param.
464 //----------------------------------------------------------------
465 #define MMCB_SONGMESSAGE 0x2A
466 //----------------------------------------------------------------
468 //----------------------------------------------------------------
469 // A module has finished playing.
470 // param == 0 if main module, ==1 otherwise
471 //----------------------------------------------------------------
472 #define MMCB_SONGFINISHED 0x2B
473 //----------------------------------------------------------------
475 //=======================================================================================
476 // misc definitions / references
477 //=======================================================================================
479 // main/sub layer attributes
480 extern mm_modlayer mmLayerMain;
481 extern mm_modlayer mmLayerSub;