dropped aas, moved to maxmod
[gbajam21] / libs / maxmod / maxmod7.h
1 /****************************************************************************
2  *                                                          __              *
3  *                ____ ___  ____ __  ______ ___  ____  ____/ /              *
4  *               / __ `__ \/ __ `/ |/ / __ `__ \/ __ \/ __  /               *
5  *              / / / / / / /_/ />  </ / / / / / /_/ / /_/ /                *
6  *             /_/ /_/ /_/\__,_/_/|_/_/ /_/ /_/\____/\__,_/                 *
7  *                                                                          *
8  *                            ARM7 Definitions                              *
9  *                                                                          *
10  *         Copyright (c) 2008, Mukunda Johnson (mukunda@maxmod.org)         *
11  *                                                                          *
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.        *
15  *                                                                          *
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  ****************************************************************************/
24
25 #ifdef ARM9
26 #error "maxmod7.h is for ARM7!"
27 #endif
28
29 //----------------------------------------------------------------
30 #ifndef MAXMOD_H
31 //----------------------------------------------------------------
32
33 #define MAXMOD_H
34
35 #include <mm_types.h>
36
37 //----------------------------------------------------------------
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 //----------------------------------------------------------------
42
43 /*****************************************************************
44  * mmInstall( channel )
45  *
46  * Install Maxmod.
47  *
48  * channel : IPC/FIFO channel to use, usually 7.
49  *****************************************************************/
50  
51 void mmInstall( int fifo_channel );
52
53 /*****************************************************************
54  * mmLockChannels( mm_word bitmask )
55  *
56  * Lock audio channels from being used by Maxmod.
57  *
58  * bitmask : Bitmask of which channels should be locked.
59  * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...)
60  *****************************************************************/
61  
62 void mmLockChannels( mm_word bitmask );
63
64 /*****************************************************************
65  * mmUnlockChannels( mm_word bitmask )
66  *
67  * Unlock audio channels so Maxmod can use them.
68  *
69  * bitmask : Bitmask of which channels should be unlocked.
70  * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...)
71  *****************************************************************/
72  
73 void mmUnlockChannels( mm_word bitmask );
74
75 /*****************************************************************
76  * mmIsInitialize()
77  *
78  * Returns whether or not the system is ready for playback.
79  *****************************************************************/
80
81 mm_bool mmIsInitialized( void );
82
83 /*****************************************************************
84  * mmSelectMode( mm_mode_enum mode )
85  *
86  * Select audio mode
87  *
88  * mode:
89  *   MM_MODE_A : Hardware Mixing
90  *   MM_MODE_B : Interpolated Mixing
91  *   MM_MODE_C : Extended Mixing
92  *****************************************************************/
93  
94 void mmSelectMode( mm_mode_enum mode );
95
96 /*****************************************************************
97  * mmFrame()
98  *
99  * Work routine (called automatically)
100  *****************************************************************/
101
102 void mmFrame( void );
103
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.
107
108
109
110 /*****************************************************************
111  *
112  * Module Playback
113  *
114  *****************************************************************/
115
116
117
118 /*****************************************************************
119  * mmStart( mm_word module_ID, mm_pmode mode )
120  *
121  * Start module playback
122  *
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  *****************************************************************/
126  
127 void mmStart( mm_word module_ID, mm_pmode mode );
128
129 /*****************************************************************
130  * mmPause()
131  *
132  * Pause module playback.
133  *****************************************************************/
134  
135 void mmPause( void );
136
137 /*****************************************************************
138  * mmResume()
139  *
140  * Resume module playback
141  *****************************************************************/
142  
143 void mmResume( void );
144
145 /*****************************************************************
146  * mmStop()
147  *
148  * Stop module playback. Start again (from the beginning)
149  * with mmStart(...).
150  *****************************************************************/
151  
152 void mmStop( void );
153
154 /*****************************************************************
155  * mmPosition( mm_word position )
156  *
157  * Set playback position.
158  *
159  * position : New position in module sequence.
160  *****************************************************************/
161  
162 void mmPosition( mm_word position );
163
164 /*****************************************************************
165  * mmActive()
166  *
167  * Returns nonzero if module is playing
168  *****************************************************************/
169  
170 mm_bool mmActive( void );
171
172 /*****************************************************************
173  * mmJingle( mm_word module_ID )
174  *
175  * Play module as jingle. Jingles are limited to 4 channels only.
176  *
177  * module_ID : ID of module (defined in soundbank header)
178  *****************************************************************/
179
180 void mmJingle( mm_word module_ID );
181
182 /*****************************************************************
183  * mmActiveSub()
184  *
185  * Returns nonzero if a jingle is actively playing.
186  *****************************************************************/
187  
188 mm_bool mmActiveSub( void );
189
190 /*****************************************************************
191  * mmSetModuleVolume( mm_word volume )
192  * mmSetJingleVolume( mm_word volume )
193  *
194  * Set volume scaler for music/jingles.
195  *
196  * volume : 0->1024 = silent..normal
197  *****************************************************************/
198
199 void mmSetModuleVolume( mm_word volume );
200 void mmSetJingleVolume( mm_word volume );
201
202 /*****************************************************************
203  * mmPlayModule( mm_word address, mm_word mode, mm_word layer )
204  *
205  * Play direct MAS file
206  *****************************************************************/
207
208 void mmPlayModule( mm_word address, mm_word mode, mm_word layer );
209
210
211
212 /*****************************************************************
213  *
214  * Sound Effects
215  *
216  *****************************************************************/
217
218
219
220 /*****************************************************************
221  * mmEffect( mm_word sample_ID )
222  *
223  * Play a sound effect at its default frequency with full volume
224  * and centered panning. Effect must be loaded first via
225  * mmLoadEffect.
226  *
227  * sample_ID : Sound effect ID. (defined in soundbank header)
228  *****************************************************************/
229  
230 mm_sfxhand mmEffect( mm_word sample_ID );
231
232 /*****************************************************************
233  * mmEffectEx( mm_sound_effect* sound )
234  *
235  * Play a sound effect with the parameters supplied.
236  *
237  * sound : Sound effect attributes.
238  *****************************************************************/
239
240 mm_sfxhand mmEffectEx( mm_sound_effect* sound );
241
242 /*****************************************************************
243  * mmEffectVolume( mm_sfxhand handle, mm_word volume )
244  *
245  * Set the volume of a sound effect.
246  *
247  * handle : Sound effect handle.
248  * volume : 0->65535
249  *****************************************************************/
250  
251 void mmEffectVolume( mm_sfxhand handle, mm_word volume );
252
253 /*****************************************************************
254  * mmEffectPanning( mm_sfxhand handle, mm_word panning )
255  *
256  * Set the panning of a sound effect.
257  *
258  * handle : Sound effect handle.
259  * panning : 0->255 = left..right
260  *****************************************************************/
261  
262 void mmEffectPanning( mm_sfxhand handle, mm_byte panning );
263
264 /*****************************************************************
265  * mmEffectRate( mm_sfxhand handle, mm_word rate )
266  *
267  * Set the playback rate of an effect.
268  *
269  * handle : Sound effect handle.
270  * rate: 6.10 factor
271  *****************************************************************/
272  
273 void mmEffectRate( mm_sfxhand handle, mm_word rate );
274
275 /*****************************************************************
276  * mmEffectScaleRate( mm_sfxhand handle, mm_word factor )
277  *
278  * Scale the playback rate of an effect.
279  *
280  * handle : Sound effect handle.
281  * factor : 6.10 fixed point factor.
282  *****************************************************************/
283  
284 void mmEffectScaleRate( mm_sfxhand handle, mm_word factor );
285
286 /*****************************************************************
287  * mmEffectCancel( mm_sfxhand handle )
288  *
289  * Stop sound effect.
290  *
291  * handle : Sound effect handle.
292  *****************************************************************/
293
294 void mmEffectCancel( mm_sfxhand handle );
295
296 /*****************************************************************
297  * mmEffectRelease( mm_sfxhand handle )
298  *
299  * Release sound effect (invalidate handle and allow interruption)
300  *
301  * handle : Sound effect handle.
302  *****************************************************************/
303  
304 void mmEffectRelease( mm_sfxhand handle );
305
306 /*****************************************************************
307  * mmSetEffectsVolume( mm_word volume )
308  *
309  * Set master volume scale for effect playback.
310  *
311  * volume : 0->1024 representing 0%->100% volume
312  *****************************************************************/
313
314 void mmSetEffectsVolume( mm_word volume );
315
316 /*****************************************************************
317  * mmEffectCancelAll()
318  *
319  * Stop all sound effects
320  *****************************************************************/
321  
322 void mmEffectCancelAll();
323
324
325
326 /*****************************************************************
327  *
328  * Streaming
329  *
330  *****************************************************************/
331
332
333 /*****************************************************************
334  * mmStreamOpen( mm_stream* stream, mm_addr wavebuffer, mm_addr workbuffer )
335  *
336  * Open audio stream.
337  *
338  * stream : Configuration struct
339  * wavebuffer : wave memory, must be aligned
340  * workbuffer : work memory, must be aligned
341  *****************************************************************/
342
343 void mmStreamOpen( mm_stream* stream, mm_addr wavebuffer, mm_addr workbuffer );
344
345 /*****************************************************************
346  * mmStreamUpdate()
347  *
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  *****************************************************************/
352
353 void mmStreamUpdate( void );
354
355 /*****************************************************************
356  * mmStreamClose()
357  *
358  * Close audio stream.
359  *****************************************************************/
360
361 void mmStreamClose( void );
362
363 /*****************************************************************
364  * mmStreamGetPosition()
365  *
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  *****************************************************************/
369  
370 mm_word mmStreamGetPosition();
371
372
373
374 /*****************************************************************
375  *
376  * Reverb
377  *
378  *****************************************************************/
379  
380  
381
382 /*****************************************************************
383  * mmReverbEnable()
384  *
385  * Enable reverb system. (use before configuring!)
386  *****************************************************************/
387  
388 void mmReverbEnable( void );
389  
390 /*****************************************************************
391  * mmReverbConfigure( mm_reverb_cfg* config )
392  *
393  * Configure reverb parameters.
394  * config : Configuration data.
395  *****************************************************************/
396  
397 void mmReverbConfigure( mm_reverb_cfg* config );
398
399 /*****************************************************************
400  * mmReverbStart( mm_reverbch channels )
401  *
402  * Start reverb output.
403  *****************************************************************/
404
405 void mmReverbStart( mm_reverbch channels );
406
407 /*****************************************************************
408  * mmReverbStop( mm_reverch channels )
409  *
410  * Stop reverb output.
411  *****************************************************************/
412
413 void mmReverbStop( mm_reverbch channels );
414
415 /*****************************************************************
416  * mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate,
417  *                     mm_word delay )
418  *
419  * Calculate reverb buffer size based on bit depth, delay
420  * and sampling rate.
421  *
422  * bit_depth : Pass 8 or 16 for 8-bit/16-bit
423  * sampling_rate :
424  * delay : In milliseconds
425  *
426  * Returns size in WORDS.
427  *****************************************************************/
428
429 static inline mm_word mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate, mm_word delay )
430 {
431         if( bit_depth == 16 )
432         {
433                 return ((((sampling_rate * delay * 2) / 1000) + 3) & (~3)) / 4;
434         }
435         else
436         {
437                 return ((((sampling_rate * delay) / 1000) + 3) & (~3)) / 4;
438         }
439 }
440
441 /*****************************************************************
442  * mmReverbDisable()
443  *
444  * Disable reverb system.
445  *****************************************************************/
446
447 void mmReverbDisable( void );
448
449
450
451 //----------------------------------------------------------------
452 #ifdef __cplusplus
453 }
454 #endif
455 //----------------------------------------------------------------
456
457 /*****************************************************************
458  * Playback events
459  *****************************************************************/
460
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 //----------------------------------------------------------------
467
468 //----------------------------------------------------------------
469 // A module has finished playing.
470 // param == 0 if main module, ==1 otherwise
471 //----------------------------------------------------------------
472 #define MMCB_SONGFINISHED       0x2B
473 //----------------------------------------------------------------
474
475 //=======================================================================================
476 // misc definitions / references
477 //=======================================================================================
478
479 // main/sub layer attributes
480 extern mm_modlayer mmLayerMain;
481 extern mm_modlayer mmLayerSub;
482
483 #endif