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 ****************************************************************************/
34 // precalculated mix buffer lengths (in bytes)
35 #define MM_MIXLEN_8KHZ 544 // (8121 hz)
36 #define MM_MIXLEN_10KHZ 704 // (10512 hz)
37 #define MM_MIXLEN_13KHZ 896 // (13379 hz)
38 #define MM_MIXLEN_16KHZ 1056 // (15768 hz)
39 #define MM_MIXLEN_18KHZ 1216 // (18157 hz)
40 #define MM_MIXLEN_21KHZ 1408 // (21024 hz)
41 #define MM_MIXLEN_27KHZ 1792 // (26758 hz)
42 #define MM_MIXLEN_31KHZ 2112 // (31536 hz)
44 // measurements of channel types (bytes)
45 #define MM_SIZEOF_MODCH 40
46 #define MM_SIZEOF_ACTCH 28
47 #define MM_SIZEOF_MIXCH 24
49 /****************************************************************************
50 * mmInitDefault( mm_addr soundbank, mm_word number_of_channels )
52 * Initialize Maxmod with default settings.
53 ****************************************************************************/
55 void mmInitDefault( mm_addr soundbank, mm_word number_of_channels );
57 /****************************************************************************
58 * mmInit( mm_gba_system* setup )
60 * Initialize system. Call once at startup.
61 ****************************************************************************/
63 void mmInit( mm_gba_system* setup );
65 /****************************************************************************
68 * Must be linked to the VBlank IRQ.
69 ****************************************************************************/
71 void mmVBlank( void );
73 /****************************************************************************
74 * mmSetVBlankHandler( void* function )
76 * Install user vblank handler
78 * function : Pointer to your VBlank handler.
79 ****************************************************************************/
81 void mmSetVBlankHandler( void* function );
83 /****************************************************************************
84 * mmSetEventHandler( mm_callback handler )
86 * Install handler to receive song events.
87 ****************************************************************************/
89 void mmSetEventHandler( mm_callback handler );
91 /****************************************************************************
94 * Work routine. _Must_ be called every frame.
95 ****************************************************************************/
97 void mmFrame( void ) __attribute((long_call));
101 /****************************************************************************
105 ****************************************************************************/
109 /****************************************************************************
110 * mmStart( mm_word id, mm_pmode mode )
112 * Start module playback.
114 * id : ID of module to play.
115 * mode : Playback mode (loop/once)
116 ****************************************************************************/
118 void mmStart( mm_word id, mm_pmode mode );
120 /****************************************************************************
123 * Pause module playback, resume with mmResume().
124 ****************************************************************************/
126 void mmPause( void );
128 /****************************************************************************
131 * Resume module playback, pause with mmPause().
132 ****************************************************************************/
134 void mmResume( void );
136 /****************************************************************************
139 * Stop module playback. start again with mmStart().
140 ****************************************************************************/
144 /****************************************************************************
147 * Get playback position.
148 ****************************************************************************/
150 mm_word mmGetPosition( void );
152 /****************************************************************************
155 * Set playback position.
157 * position: New position in the module sequence.
158 ****************************************************************************/
160 void mmPosition( mm_word position );
162 /****************************************************************************
165 * Set playback position (alias for mmPosition()).
167 * position: New position in the module sequence.
168 ****************************************************************************/
170 inline void mmSetPosition( mm_word position )
172 mmPosition( position );
175 /****************************************************************************
178 * Returns nonzero if module is playing.
179 ****************************************************************************/
181 int mmActive( void );
183 /****************************************************************************
184 * mmJingle( mm_word module_ID )
186 * Play module as jingle. Jingles are limited to 4 channels only.
188 * module_ID : ID of moudle (defined in soundbank header)
189 ****************************************************************************/
191 void mmJingle( mm_word module_ID );
193 /****************************************************************************
196 * Returns nonzero if a jingle is actively playing.
197 ****************************************************************************/
199 int mmActiveSub( void );
201 /****************************************************************************
202 * mmSetModuleVolume( mm_word volume )
203 * mmSetJingleVolume( mm_word volume )
205 * Set volume scaler for music/jingles.
207 * volume : 0->1024 = silent..normal
208 ****************************************************************************/
210 void mmSetModuleVolume( mm_word volume );
211 void mmSetJingleVolume( mm_word volume );
213 /*****************************************************************
214 * mmSetModuleTempo( mm_word tempo )
216 * Set tempo of playback.
218 * tempo : Fixed point (Q10) value representing tempo.
219 * Range = 0x200 -> 0x800 = 0.5 -> 2.0
220 *****************************************************************/
222 void mmSetModuleTempo( mm_word tempo );
224 /*****************************************************************
225 * mmSetModulePitch( mm_word pitch )
227 * Set pitch of playback.
229 * pitch : Range = 0x200 -> 0x800 = 0.5 -> 2.0
230 *****************************************************************/
232 void mmSetModulePitch( mm_word pitch );
234 /****************************************************************************
235 * mmPlayModule( mm_word address, mm_word mode, mm_word layer )
237 * Play direct MAS file
238 ****************************************************************************/
240 void mmPlayModule( mm_word address, mm_word mode, mm_word layer );
244 /****************************************************************************
248 ****************************************************************************/
252 /****************************************************************************
253 * mmEffect( mm_word sample_ID )
255 * Play a sound effect at its default frequency with full volume and
258 * sample_ID : Sound effect ID. (defined in soundbank header)
259 ****************************************************************************/
261 mm_sfxhand mmEffect( mm_word sample_ID );
263 /****************************************************************************
264 * mmEffectEx( mm_sound_effect* sound )
266 * Play a sound effect with all parameters.
268 * sound : Sound effect attributes.
269 ****************************************************************************/
271 mm_sfxhand mmEffectEx( mm_sound_effect* sound );
273 /****************************************************************************
274 * mmEffectVolume( mm_sfxhand handle, mm_word volume )
276 * Set the volume of a sound effect.
278 * handle : Sound effect handle.
280 ****************************************************************************/
282 void mmEffectVolume( mm_sfxhand handle, mm_word volume );
284 /****************************************************************************
285 * mmEffectPanning( mm_sfxhand handle, mm_word panning )
287 * Set the panning of a sound effect.
289 * handle : Sound effect handle.
290 * panning : 0->255 = left..right
291 ****************************************************************************/
293 void mmEffectPanning( mm_sfxhand handle, mm_byte panning );
295 /****************************************************************************
296 * mmEffectRate( mm_sfxhand handle, mm_word rate )
298 * Set the playback rate of an effect.
300 * handle : Sound effect handle.
302 ****************************************************************************/
304 void mmEffectRate( mm_sfxhand handle, mm_word rate );
306 /****************************************************************************
307 * mmEffectScaleRate( mm_sfxhand handle, mm_word factor )
309 * Scale the playback rate of an effect.
311 * handle : Sound effect handle.
312 * factor : 6.10 fixed point factor.
313 ****************************************************************************/
315 void mmEffectScaleRate( mm_sfxhand handle, mm_word factor );
317 /****************************************************************************
318 * mmEffectActive( mm_sfxhand handle )
320 * Indicates if a sound effect is active or not.
322 * handle : Sound effect handle.
323 ****************************************************************************/
325 mm_bool mmEffectActive( mm_sfxhand handle );
327 /****************************************************************************
328 * mmEffectCancel( mm_sfxhand handle )
332 * handle : Sound effect handle.
333 ****************************************************************************/
335 void mmEffectCancel( mm_sfxhand handle );
337 /****************************************************************************
338 * mmEffectRelease( mm_sfxhand handle )
340 * Release sound effect (invalidate handle and allow interruption)
342 * handle : Sound effect handle.
343 ****************************************************************************/
345 void mmEffectRelease( mm_sfxhand handle );
347 /****************************************************************************
348 * mmSetEffectsVolume( mm_word volume )
350 * Set master volume scale for effect playback.
352 * volume : 0->1024 representing 0%->100% volume
353 ****************************************************************************/
355 void mmSetEffectsVolume( mm_word volume );
357 /****************************************************************************
358 * mmEffectCancelAll()
360 * Stop all sound effects
361 ****************************************************************************/
363 void mmEffectCancelAll();
371 /****************************************************************************
373 ****************************************************************************/
375 //---------------------------------------------------------------------------
376 // This happens when Maxmod reads a SFx (or mod/xm EFx) effect from a module
377 // It will store 'x' in param_b
378 //---------------------------------------------------------------------------
379 #define MMCB_SONGMESSAGE 0x2A
380 //---------------------------------------------------------------------------
382 //---------------------------------------------------------------------------
383 // A module has finished playing
384 // param == 0 if main module, ==1 otherwise
385 //---------------------------------------------------------------------------
386 #define MMCB_SONGFINISHED 0x2B
387 //---------------------------------------------------------------------------
389 /****************************************************************************
391 ****************************************************************************/
393 extern mm_byte mp_mix_seg; // current mixing segment
394 extern mm_word mp_writepos; // mixer's write position