00001 /**************************************************************************** 00002 * __ * 00003 * ____ ___ ____ __ ______ ___ ____ ____/ / * 00004 * / __ `__ \/ __ `/ |/ / __ `__ \/ __ \/ __ / * 00005 * / / / / / / /_/ /> </ / / / / / /_/ / /_/ / * 00006 * /_/ /_/ /_/\__,_/_/|_/_/ /_/ /_/\____/\__,_/ * 00007 * * 00008 * ARM7 Definitions * 00009 * * 00010 * Copyright (c) 2008, Mukunda Johnson (mukunda@maxmod.org) * 00011 * * 00012 * Permission to use, copy, modify, and/or distribute this software for any * 00013 * purpose with or without fee is hereby granted, provided that the above * 00014 * copyright notice and this permission notice appear in all copies. * 00015 * * 00016 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * 00017 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * 00018 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * 00019 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * 00020 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * 00021 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * 00022 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 00023 ****************************************************************************/ 00024 00025 #ifdef ARM9 00026 #error "maxmod7.h is for ARM7!" 00027 #endif 00028 00029 //---------------------------------------------------------------- 00030 #ifndef MAXMOD_H 00031 //---------------------------------------------------------------- 00032 00033 #define MAXMOD_H 00034 00035 #include <mm_types.h> 00036 00037 //---------------------------------------------------------------- 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 //---------------------------------------------------------------- 00042 00043 /***************************************************************** 00044 * mmInstall( channel ) 00045 * 00046 * Install Maxmod. 00047 * 00048 * channel : IPC/FIFO channel to use, usually 7. 00049 *****************************************************************/ 00050 00051 void mmInstall( int fifo_channel ); 00052 00053 /***************************************************************** 00054 * mmLockChannels( mm_word bitmask ) 00055 * 00056 * Lock audio channels from being used by Maxmod. 00057 * 00058 * bitmask : Bitmask of which channels should be locked. 00059 * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...) 00060 *****************************************************************/ 00061 00062 void mmLockChannels( mm_word bitmask ); 00063 00064 /***************************************************************** 00065 * mmUnlockChannels( mm_word bitmask ) 00066 * 00067 * Unlock audio channels so Maxmod can use them. 00068 * 00069 * bitmask : Bitmask of which channels should be unlocked. 00070 * (&1 = ch0, &2 = ch1, &4 = ch2, &8 = ch4, etc...) 00071 *****************************************************************/ 00072 00073 void mmUnlockChannels( mm_word bitmask ); 00074 00075 /***************************************************************** 00076 * mmIsInitialize() 00077 * 00078 * Returns whether or not the system is ready for playback. 00079 *****************************************************************/ 00080 00081 mm_bool mmIsInitialized( void ); 00082 00083 /***************************************************************** 00084 * mmSelectMode( mm_mode_enum mode ) 00085 * 00086 * Select audio mode 00087 * 00088 * mode: 00089 * MM_MODE_A : Hardware Mixing 00090 * MM_MODE_B : Interpolated Mixing 00091 * MM_MODE_C : Extended Mixing 00092 *****************************************************************/ 00093 00094 void mmSelectMode( mm_mode_enum mode ); 00095 00096 /***************************************************************** 00097 * mmFrame() 00098 * 00099 * Work routine (called automatically) 00100 *****************************************************************/ 00101 00102 void mmFrame( void ); 00103 00104 // note about using sleep functions: 00105 // do not use during an interrupt!! it's not safe 00106 // and do not exit sleep unless it is already sleeping. 00107 00108 00109 00110 /***************************************************************** 00111 * 00112 * Module Playback 00113 * 00114 *****************************************************************/ 00115 00116 00117 00118 /***************************************************************** 00119 * mmStart( mm_word module_ID, mm_pmode mode ) 00120 * 00121 * Start module playback 00122 * 00123 * module_ID : Index of module to play. (defined in soundbank header) 00124 * mode : Mode of playback: MM_PLAY_ONCE or MM_PLAY_LOOP 00125 *****************************************************************/ 00126 00127 void mmStart( mm_word module_ID, mm_pmode mode ); 00128 00129 /***************************************************************** 00130 * mmPause() 00131 * 00132 * Pause module playback. 00133 *****************************************************************/ 00134 00135 void mmPause( void ); 00136 00137 /***************************************************************** 00138 * mmResume() 00139 * 00140 * Resume module playback 00141 *****************************************************************/ 00142 00143 void mmResume( void ); 00144 00145 /***************************************************************** 00146 * mmStop() 00147 * 00148 * Stop module playback. Start again (from the beginning) 00149 * with mmStart(...). 00150 *****************************************************************/ 00151 00152 void mmStop( void ); 00153 00154 /***************************************************************** 00155 * mmPosition( mm_word position ) 00156 * 00157 * Set playback position. 00158 * 00159 * position : New position in module sequence. 00160 *****************************************************************/ 00161 00162 void mmPosition( mm_word position ); 00163 00164 /***************************************************************** 00165 * mmActive() 00166 * 00167 * Returns nonzero if module is playing 00168 *****************************************************************/ 00169 00170 mm_bool mmActive( void ); 00171 00172 /***************************************************************** 00173 * mmJingle( mm_word module_ID ) 00174 * 00175 * Play module as jingle. Jingles are limited to 4 channels only. 00176 * 00177 * module_ID : ID of module (defined in soundbank header) 00178 *****************************************************************/ 00179 00180 void mmJingle( mm_word module_ID ); 00181 00182 /***************************************************************** 00183 * mmActiveSub() 00184 * 00185 * Returns nonzero if a jingle is actively playing. 00186 *****************************************************************/ 00187 00188 mm_bool mmActiveSub( void ); 00189 00190 /***************************************************************** 00191 * mmSetModuleVolume( mm_word volume ) 00192 * mmSetJingleVolume( mm_word volume ) 00193 * 00194 * Set volume scaler for music/jingles. 00195 * 00196 * volume : 0->1024 = silent..normal 00197 *****************************************************************/ 00198 00199 void mmSetModuleVolume( mm_word volume ); 00200 void mmSetJingleVolume( mm_word volume ); 00201 00202 /***************************************************************** 00203 * mmPlayModule( mm_word address, mm_word mode, mm_word layer ) 00204 * 00205 * Play direct MAS file 00206 *****************************************************************/ 00207 00208 void mmPlayModule( mm_word address, mm_word mode, mm_word layer ); 00209 00210 00211 00212 /***************************************************************** 00213 * 00214 * Sound Effects 00215 * 00216 *****************************************************************/ 00217 00218 00219 00220 /***************************************************************** 00221 * mmEffect( mm_word sample_ID ) 00222 * 00223 * Play a sound effect at its default frequency with full volume 00224 * and centered panning. Effect must be loaded first via 00225 * mmLoadEffect. 00226 * 00227 * sample_ID : Sound effect ID. (defined in soundbank header) 00228 *****************************************************************/ 00229 00230 mm_sfxhand mmEffect( mm_word sample_ID ); 00231 00232 /***************************************************************** 00233 * mmEffectEx( mm_sound_effect* sound ) 00234 * 00235 * Play a sound effect with the parameters supplied. 00236 * 00237 * sound : Sound effect attributes. 00238 *****************************************************************/ 00239 00240 mm_sfxhand mmEffectEx( mm_sound_effect* sound ); 00241 00242 /***************************************************************** 00243 * mmEffectVolume( mm_sfxhand handle, mm_word volume ) 00244 * 00245 * Set the volume of a sound effect. 00246 * 00247 * handle : Sound effect handle. 00248 * volume : 0->65535 00249 *****************************************************************/ 00250 00251 void mmEffectVolume( mm_sfxhand handle, mm_word volume ); 00252 00253 /***************************************************************** 00254 * mmEffectPanning( mm_sfxhand handle, mm_word panning ) 00255 * 00256 * Set the panning of a sound effect. 00257 * 00258 * handle : Sound effect handle. 00259 * panning : 0->255 = left..right 00260 *****************************************************************/ 00261 00262 void mmEffectPanning( mm_sfxhand handle, mm_byte panning ); 00263 00264 /***************************************************************** 00265 * mmEffectRate( mm_sfxhand handle, mm_word rate ) 00266 * 00267 * Set the playback rate of an effect. 00268 * 00269 * handle : Sound effect handle. 00270 * rate: 6.10 factor 00271 *****************************************************************/ 00272 00273 void mmEffectRate( mm_sfxhand handle, mm_word rate ); 00274 00275 /***************************************************************** 00276 * mmEffectScaleRate( mm_sfxhand handle, mm_word factor ) 00277 * 00278 * Scale the playback rate of an effect. 00279 * 00280 * handle : Sound effect handle. 00281 * factor : 6.10 fixed point factor. 00282 *****************************************************************/ 00283 00284 void mmEffectScaleRate( mm_sfxhand handle, mm_word factor ); 00285 00286 /***************************************************************** 00287 * mmEffectCancel( mm_sfxhand handle ) 00288 * 00289 * Stop sound effect. 00290 * 00291 * handle : Sound effect handle. 00292 *****************************************************************/ 00293 00294 void mmEffectCancel( mm_sfxhand handle ); 00295 00296 /***************************************************************** 00297 * mmEffectRelease( mm_sfxhand handle ) 00298 * 00299 * Release sound effect (invalidate handle and allow interruption) 00300 * 00301 * handle : Sound effect handle. 00302 *****************************************************************/ 00303 00304 void mmEffectRelease( mm_sfxhand handle ); 00305 00306 /***************************************************************** 00307 * mmSetEffectsVolume( mm_word volume ) 00308 * 00309 * Set master volume scale for effect playback. 00310 * 00311 * volume : 0->1024 representing 0%->100% volume 00312 *****************************************************************/ 00313 00314 void mmSetEffectsVolume( mm_word volume ); 00315 00316 /***************************************************************** 00317 * mmEffectCancelAll() 00318 * 00319 * Stop all sound effects 00320 *****************************************************************/ 00321 00322 void mmEffectCancelAll(); 00323 00324 00325 00326 /***************************************************************** 00327 * 00328 * Streaming 00329 * 00330 *****************************************************************/ 00331 00332 00333 /***************************************************************** 00334 * mmStreamOpen( mm_stream* stream, mm_addr wavebuffer, mm_addr workbuffer ) 00335 * 00336 * Open audio stream. 00337 * 00338 * stream : Configuration struct 00339 * wavebuffer : wave memory, must be aligned 00340 * workbuffer : work memory, must be aligned 00341 *****************************************************************/ 00342 00343 void mmStreamOpen( mm_stream* stream, mm_addr memory ); 00344 00345 /***************************************************************** 00346 * mmStreamUpdate() 00347 * 00348 * Fills the stream with wave data. 00349 * This only needs to be called in 'manual' mode. It 00350 * is called automatically in 'auto' mode. 00351 *****************************************************************/ 00352 00353 void mmStreamUpdate( void ); 00354 00355 /***************************************************************** 00356 * mmStreamClose() 00357 * 00358 * Close audio stream. 00359 *****************************************************************/ 00360 00361 void mmCloseStream( void ); 00362 00363 00364 00365 /***************************************************************** 00366 * 00367 * Reverb 00368 * 00369 *****************************************************************/ 00370 00371 00372 00373 /***************************************************************** 00374 * mmReverbEnable() 00375 * 00376 * Enable reverb system. (use before configuring!) 00377 *****************************************************************/ 00378 00379 void mmReverbEnable( void ); 00380 00381 /***************************************************************** 00382 * mmReverbConfigure( mm_reverb_cfg* config ) 00383 * 00384 * Configure reverb parameters. 00385 * config : Configuration data. 00386 *****************************************************************/ 00387 00388 void mmReverbConfigure( mm_reverb_cfg* config ); 00389 00390 /***************************************************************** 00391 * mmReverbStart( mm_reverbch channels ) 00392 * 00393 * Start reverb output. 00394 *****************************************************************/ 00395 00396 void mmReverbStart( mm_reverbch channels ); 00397 00398 /***************************************************************** 00399 * mmReverbStop( mm_reverch channels ) 00400 * 00401 * Stop reverb output. 00402 *****************************************************************/ 00403 00404 void mmReverbStop( mm_reverbch channels ); 00405 00406 /***************************************************************** 00407 * mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate, 00408 * mm_word delay ) 00409 * 00410 * Calculate reverb buffer size based on bit depth, delay 00411 * and sampling rate. 00412 * 00413 * bit_depth : Pass 8 or 16 for 8-bit/16-bit 00414 * sampling_rate : 00415 * delay : In milliseconds 00416 * 00417 * Returns size in WORDS. 00418 *****************************************************************/ 00419 00420 static inline mm_word mmReverbBufferSize( mm_word bit_depth, mm_word sampling_rate, mm_word delay ) 00421 { 00422 if( bit_depth == 16 ) 00423 { 00424 return ((((sampling_rate * delay * 2) / 1000) + 3) & (~3)) / 4; 00425 } 00426 else 00427 { 00428 return ((((sampling_rate * delay) / 1000) + 3) & (~3)) / 4; 00429 } 00430 } 00431 00432 /***************************************************************** 00433 * mmReverbDisable() 00434 * 00435 * Disable reverb system. 00436 *****************************************************************/ 00437 00438 void mmReverbDisable( void ); 00439 00440 00441 00442 //---------------------------------------------------------------- 00443 #ifdef __cplusplus 00444 } 00445 #endif 00446 //---------------------------------------------------------------- 00447 00448 /***************************************************************** 00449 * Playback events 00450 *****************************************************************/ 00451 00452 //---------------------------------------------------------------- 00453 // This happens when Maxmod reads an SFx (or mod/xm EFx) effect 00454 // from a module. It will pass 'x' in param. 00455 //---------------------------------------------------------------- 00456 #define MMCB_SONGMESSAGE 0x2A 00457 //---------------------------------------------------------------- 00458 00459 //---------------------------------------------------------------- 00460 // A module has finished playing. 00461 // param == 0 if main module, ==1 otherwise 00462 //---------------------------------------------------------------- 00463 #define MMCB_SONGFINISHED 0x2B 00464 //---------------------------------------------------------------- 00465 00466 //======================================================================================= 00467 // misc definitions / references 00468 //======================================================================================= 00469 00470 // main/sub layer attributes 00471 extern mm_modlayer mmLayerMain; 00472 extern mm_modlayer mmLayerSub; 00473 00474 #endif