DSGM_SoundInstance *DSGM_PlaySoundAdvancedFull(DSGM_Sound *sound, u8 volume, u8 panning) { DSGM_SoundInstance *soundInstance = DSGM_AddSoundInstance(sound); if(sound->type == DSGM_SOUND_STREAM) { if(!sound->loaded) { mmLoad(sound->ID); sound->loaded = true; } mmStart(sound->ID, MM_PLAY_LOOP); } else { if(!sound->loaded) { mmLoadEffect(sound->ID - DSGM_soundStreamCount); sound->loaded = true; } mm_sound_effect effect = { { sound->ID - DSGM_soundStreamCount } , (int)(1.0f * (1<<10)), // rate 0, // handle soundInstance->volume = volume, // volume (255 = max) soundInstance->panning = panning, // panning (128 = center) }; soundInstance->effectNumber = mmEffectEx(&effect); mmEffectRelease(soundInstance->effectNumber); } return soundInstance; }
Sound::Sound() { mmInitDefaultMem((mm_addr)soundbank_bin); mmLoad(MOD_CASTLE_MUSIC); mmStart(MOD_CASTLE_MUSIC, MM_PLAY_LOOP); initEffects(); }
/* Initialisation ************************************************************* * -------------- * Paramètres : * - parts : les parts qui devront être jouées * - nb_parts : le nombre de parts ******************************************************************************/ void DemoInit(T_Part* parts, int nb_parts) { TimerMillis = 0; DemoParts = parts; NbParts = nb_parts; CurrentPart = 0; mmInitDefaultMem( (mm_addr)soundbank_bin ); mmSelectMode(MM_MODE_C); mmLoad(0); // Initialisation du timer // Millisecond Timer refresh IRQ TIMER1_CR = 0; TIMER1_DATA = TIMER_FREQ(0x409); TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ; irqEnable(IRQ_TIMER1); irqSet(IRQ_TIMER1, _TimerMillisInterrupt); glInit(); }
DSGM_SoundInstance *DSGM_PlaySoundFull(DSGM_Sound *sound) { DSGM_SoundInstance *soundInstance = DSGM_AddSoundInstance(sound); if(sound->type == DSGM_SOUND_STREAM) { if(!sound->loaded) { mmLoad(sound->ID); sound->loaded = true; } mmStart(sound->ID, MM_PLAY_LOOP); } else { if(!sound->loaded) { mmLoadEffect(sound->ID - DSGM_soundStreamCount); sound->loaded = true; } soundInstance->effectNumber = mmEffect(sound->ID - DSGM_soundStreamCount); mmEffectRelease(soundInstance->effectNumber); } soundInstance->volume = 255; soundInstance->panning = 128; return soundInstance; }
// Program entrypoint int main() { if (!mmIsARM7Loaded()) { printf("Couldn't load Maxmod!\n"); return 1; } // Init Maxmod with default settings (loading from FAR) mmInitDefaultFAR(hFar, "/soundbank.bin"); FeOS_DirectMode(); videoSetMode(MODE_0_2D); videoSetModeSub(0); vramSetBankA(VRAM_A_MAIN_SPRITE); // Initialize the sprite engine with 1D mapping 128 byte boundary // aand no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); int i; for (i = 0; i < 5; i ++) { // Allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); // Fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords(((i+1) << 8) | (i+1), sprites[i].gfx, 32*32); } // Set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); mmSetEventHandler(myEventHandler); mmLoad(MOD_EXAMPLE2); mmStart(MOD_EXAMPLE2, MM_PLAY_LOOP); for(;;) { swiWaitForVBlank(); if (keysDown() & KEY_START) break; for (i = 0; i < 5; i ++) { // Constantly increase the sprite's y velocity sprites[i].dy += 1; // Update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // Clamp the sprite's y position if (sprites[i].y<72) sprites[i].y = 72; if (sprites[i].y>96) sprites[i].y = 96; oamSet(&oamMain, // Main graphics engine context i, // OAM index (0 to 127) sprites[i].x, // X and Y pixel location of the sprite sprites[i].y, 0, // Priority, lower renders last (on top) sprites[i].paletteAlpha, // Palette index sprites[i].size, sprites[i].format, sprites[i].gfx, // Pointer to the loaded graphics sprites[i].rotationIndex, // Sprite rotation data false, // Double the size when rotating? false, // Hide the sprite? false, false, // VFlip, HFlip false); // Apply mosaic } } mmStop(); mmUnload(MOD_EXAMPLE2); mmUnloadSoundbank(); FeOS_ConsoleMode(); return 0; }
Music::Music(mm_word music) : music(music) { mmLoad(music); }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; videoSetMode(MODE_0_2D); videoSetModeSub(0); // not using subscreen lcdMainOnBottom(); //initialize the sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); vramSetBankA(VRAM_A_MAIN_SPRITE); for (i = 0; i < 5; i++) { //allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); //fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords( ((i+1)<<8)|(i+1), sprites[i].gfx, 32*32); } //set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); // initialise maxmod using default settings, and enable interface for soundbank that is loaded into memory mmInitDefaultMem( (mm_addr)mmsolution_bin ); // setup maxmod to use the song event handler mmSetEventHandler( myEventHandler ); // load song // values for this function are in the solution header mmLoad( MOD_EXAMPLE2 ); // start song playing mmStart( MOD_EXAMPLE2, MM_PLAY_LOOP ); while(1) { for (i=0; i < 5; i++) { // constantly increase the sprite's y velocity sprites[i].dy += 1; // update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // clamp the sprite's y position if ( sprites[i].y<72 ) sprites[i].y = 72; if ( sprites[i].y>96 ) sprites[i].y = 96; oamSet( &oamMain, //main graphics engine context i, //oam index (0 to 127) sprites[i].x, //x and y pixel location of the sprite sprites[i].y, 0, //priority, lower renders last (on top) sprites[i].paletteAlpha, //palette index sprites[i].size, sprites[i].format, sprites[i].gfx, //pointer to the loaded graphics sprites[i].rotationIndex, //sprite rotation data false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); } swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamMain); } return 0; }