//------------------------------------------------------------------------------ //! \brief Play a module (called from the game) //! //! \param id = SMOD_xxx id //------------------------------------------------------------------------------ void CAudioDrv::PlayModule(int id) { if (!m_AudioValidFlag) return; if (m_DisableMusicFlag) return; MODPlay_Stop(&methane_music); if (m_DisableMusicFlag) id = SMOD_EMPTY; switch(id) { case SMOD_TUNE1: MODPlay_SetMOD(&methane_music, tune1_mod); break; case SMOD_TUNE2: MODPlay_SetMOD(&methane_music, tune2_mod); break; case SMOD_BOSS: MODPlay_SetMOD(&methane_music, boss_mod); break; case SMOD_COMPLETE: MODPlay_SetMOD(&methane_music, complete_mod); break; case SMOD_TITLE: MODPlay_SetMOD(&methane_music, title_mod); break; default: MODPlay_SetMOD(&methane_music, empty_mod); break; } // Set the volume, cause it resets on every new mod MODPlay_SetVolume(&methane_music, music_volume, music_volume); MODPlay_Start(&methane_music); }
int main(int argc, char* argv[]) { u8 *tex_ptrone=GRRLIB_LoadTexture(handpointerred_png); u8 *tex_ptrtwo=GRRLIB_LoadTexture(handpointergreen_png); u8 *tex_back=GRRLIB_LoadJPG(bigmenuback_jpg, bigmenuback_jpg_size); u8 *tex_fore=GRRLIB_LoadTexture(credits_png); fatInitDefault(); GRRLIB_InitVideo(); WPAD_Init(); SYS_SetResetCallback(WiiResetPressed); SYS_SetPowerCallback(WiiPowerPressed); WPAD_SetPowerButtonCallback(WiimotePowerPressed); rmode = VIDEO_GetPreferredMode(NULL); AESND_Init(NULL); MODPlay_Init(&mod_track); Init_Voice(); AESND_Pause(0); // the sound loop is running now // set the MOD song if (MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod) < 0 ) { MODPlay_Unload (&mod_track); } else { // set the music volume to the minimum so we don't hear the music before saved volume is known MODPlay_SetVolume( &mod_track, 0,0); MODPlay_Start (&mod_track);// Play the MOD } WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight); initMain(); MODPlay_SetVolume( &mod_track, opt_music, opt_music); while( HWButton == 0) { WPAD_ScanPads(); u32 wpad_one_down = WPAD_ButtonsDown(0); u32 wpad_two_down = WPAD_ButtonsDown(1); u32 type; WPADData *wd_one, *wd_two; WPAD_ReadPending(WPAD_CHAN_ALL, countevs); WPAD_Probe(WPAD_CHAN_ALL, &type); wd_one = WPAD_Data(0); wd_two = WPAD_Data(1); switch(main_mode) { case STARTUP : GRRLIB_FillScreen(0xFF000000); GRRLIB_DrawImg(0, 0, 640, 480, tex_back, 0, 1, 1, alpha>255?255:alpha); GRRLIB_DrawImg(68,308, 256, 80, tex_fore, 0, 1, 1, alpha>255?255:alpha); if(alpha++>394 || wpad_one_down > 0) { main_mode=MENU; if(tex_back) free(tex_back); if(tex_fore) free(tex_fore); initMenu(); } break; case MENU : GRRLIB_FillScreen(0xFF000000); int menuopt = menuWiimote(wd_one,wpad_one_down); if(menuopt==EXIT) { if(tex_ptrone) free(tex_ptrone); if(tex_ptrtwo) free(tex_ptrtwo); } if(menuopt>NOTHING) { processMenuOption(menuopt); if(main_mode==GAME) { MODPlay_Unload (&mod_track); if(opt_tileset==SPOOKY) MODPlay_SetMOD (&mod_track, graveyard_mod); else if(opt_tileset==EGYPTIAN) MODPlay_SetMOD (&mod_track, egypt_crap_mod); else if(opt_tileset==SIMPLE) MODPlay_SetMOD (&mod_track, childhood_mod); else if(opt_tileset==SPACE) MODPlay_SetMOD (&mod_track, nebulos_mod); else MODPlay_SetMOD (&mod_track, sushi_mod); MODPlay_SetVolume( &mod_track, opt_music, opt_music); MODPlay_Start (&mod_track); } else drawMenu(wd_one); } else drawMenu(wd_one); break; case GAME : if(gameWiimote(wd_one,wpad_one_down,wd_two,wpad_two_down)) { // we are exiting the game back to the menu main_mode=MENU; MODPlay_Unload (&mod_track); MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod); MODPlay_SetVolume( &mod_track, opt_music, opt_music); MODPlay_Start (&mod_track); killGame(); initMenu(); } else { drawGame(); } break; } // alternate which pointer is on top every frame to not give the advantage to player one in two player mode static int ticktock=0; ticktock++; if(wd_two->ir.valid && ticktock%2==0) { if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) { // don't display second pointer in one player mode } else GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF); } if(wd_one->ir.valid) { GRRLIB_DrawColImg(wd_one->ir.x - 9,wd_one->ir.y - 7,68,80,tex_ptrone,0,1,1,0xEEFFFFFF); } if(wd_two->ir.valid && ticktock%2!=0) { if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) { // don't display second pointer in one player mode } else GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF); } if(wd_one->btns_h & WPAD_BUTTON_1) { GRRLIB_ScrShot("MahjonggWii_Screen_%y%m%d_%H%M%S.png",time(NULL)); } GRRLIB_Render(); } // we are exiting, free the mallocs switch( main_mode) { case GAME: killGame(); } if(tex_ptrone) free(tex_ptrone); if(tex_ptrtwo) free(tex_ptrtwo); killMenuLanguages(); MODPlay_Unload (&mod_track); Free_Voice(); WPAD_Shutdown(); GRRLIB_Stop(); saveConfig(FILE_CFG); SYS_ResetSystem(HWButton, 0, 0); return 0; }
void _Music_Start() { int ret; // always init SND, so banner sounds play if music disabled ASND_Init(); ASND_Pause(0); if (CFG.music == 0) { dbg_printf(gt("Music: Disabled")); dbg_printf("\n"); return; } else { dbg_printf(gt("Music: Enabled")); dbg_printf("\n"); } was_playing = false; //get a music file ret = get_music_file(); if (ret==0) return; if (music_format == FORMAT_MP3) { MP3Player_Init(); MP3Player_Volume(0x80); // of 255 //ret = MP3Player_PlayBuffer(music_buf, music_size, NULL); ret = MP3Player_PlayFile(music_f, mp3_reader, NULL); dbg_printf("mp3 play: %s (%d)\n", ret? gt("ERROR"):gt("OK"), ret); if (ret) goto err_play; usleep(10000); // wait 10ms and verify if playing if (!MP3Player_IsPlaying()) { err_play: printf(gt("Error playing %s"), music_fname); printf("\n"); Music_Stop(); sleep(1); } } else { music_buf = malloc(music_size); if (!music_buf) { printf(gt("music file too big (%d) %s"), music_size, music_fname); printf("\n"); sleep(1); music_format = 0; return; } //printf("Loading...\n"); ret = fread(music_buf, music_size, 1, music_f); //printf("size: %d %d\n", music_size, ret); sleep(2); fclose(music_f); music_f = NULL; if (ret != 1) { printf(gt("error reading: %s (%d)"), music_fname, music_size); printf("\n"); sleep(2); free(music_buf); music_buf = NULL; music_size = 0; music_format = 0; return; } MODPlay_Init(&mod); ret = MODPlay_SetMOD(&mod, music_buf); dbg_printf("mod play: %s (%d)\n", ret?gt("ERROR"):gt("OK"), ret); if (ret < 0 ) { Music_Stop(); } else { MODPlay_SetVolume(&mod, 32,32); // fix the volume to 32 (max 64) MODPlay_Start(&mod); // Play the MOD } } }
enum e_cui_menu menu_option_snd(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); GRRLIB_texImg *tex_btn = GRRLIB_LoadTexture(button_png); UI_button button_sounds; UI_InitBtn(&button_sounds, 200, 280, "Mute"); button_sounds.img = tex_btn; button_sounds.font = font; UI_button button_return; UI_InitBtn(&button_return, 400, 400, "Return"); button_return.img = tex_btn; button_return.font = font; int i; UI_button button_type[4]; for(i=0;i<4;i++){ char text[7]; sprintf(text, "TYPE %c", 'A'+i); UI_InitBtn(&button_type[i], 50+150*i, 100, text); button_type[i].img = tex_btn; button_type[i].font = font; } while(!done){ cui_game_update_cursor(p_game->cursor); u32 pressed = WPAD_ButtonsDown(0); for(i=0;i<4;i++){ UI_UpdateBtn(&button_type[i], p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); } UI_UpdateBtn(&button_sounds, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_return, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); for(i=0;i<4;i++){ if(button_type[i].click){ switch(i){ case 0:MODPlay_SetMOD(&play,bg_music);MODPlay_Start(&play);break; case 1:MODPlay_SetMOD(&play,bg_music_b);MODPlay_Start(&play);break; case 2:MODPlay_SetMOD(&play,bg_music_c);MODPlay_Start(&play);break; case 3:MODPlay_SetMOD(&play,bg_music_d);MODPlay_Start(&play);break; } } } if(button_sounds.click){ p_game->is_mute = !p_game->is_mute; AESND_Pause(p_game->is_mute); } if(button_return.click){ done=true; next_state=CUI_MENU_MAIN; } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } for(i=0;i<4;i++){ UI_DrawBtn(&button_type[i]); } UI_DrawBtn(&button_sounds); UI_DrawBtn(&button_return); cui_cursor_display(p_game->cursor); GRRLIB_Render(); } free(button_sounds.text); free(button_return.text); free(button_type[0].text); free(button_type[1].text); free(button_type[2].text); free(button_type[3].text); GRRLIB_FreeTexture(tex_btn); GRRLIB_FreeTTF(font); return next_state; }
void AU_playMusic(const void* music) { MODPlay_Init(&play); MODPlay_SetMOD(&play, music); MODPlay_Start(&play); }
int main(int argc, char **argv) { GRRLIB_Init(); // Initialise the attached controllers WPAD_Init(); WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); // Initialise the audio subsystem AESND_Init(NULL); MODPlay_Init(&play); MODPlay_SetMOD(&play,bg_music); MODPlay_SetVolume(&play,63,63); MODPlay_Start(&play); cui_cursor cursor; cursor.tex[0]=GRRLIB_LoadTexture(player1_point_png); cursor.tex[1]=GRRLIB_LoadTexture(player1_grab_png); cursor.is_grabbing=false; cui_board board; ENGINE engine = FIRSTCHESS; if(engine == TSCP){ int i; for (i=0; i < CUI_TILE_NB; i++) { board.piece[i]=init_piece[i]; if(init_color[i] == 1){ board.color[i]=CUI_BLACK; }else if (init_color[i] == 6){ board.color[i]=CUI_EMPTY; }else if (init_color[i] == 0){ board.color[i]=CUI_WHITE; } } init_hash(); init_board(); open_book(); gen(); } cui_board_read_core(&board, engine); GRRLIB_SetBackgroundColour(0x030, 0x30, 0x42, 0xFF); board.tile_color1 = 0xAAAAAAFF; board.tile_color2 = 0x444444FF; board.piece_color1 = 0xAAAAAAFF; board.piece_color2 = 0x444444FF; cui_board_init(&board); cui_game game; game.board = &board; game.engine = engine; game.cursor = &cursor; game.is_mute = false; GRRLIB_texImg *tex_wallpaper = GRRLIB_LoadTexture(wall_jpg); game.tex_wallpaper = tex_wallpaper; voice = AESND_AllocateVoice(aesnd_callback); AESND_SetVoiceVolume(voice, 0xFF, 0xFF); AESND_SetVoiceStream(voice, true); cui_menu current_state = CUI_MENU_MAIN; while(current_state != CUI_MENU_EXIT) { switch(current_state){ case CUI_MENU_MAIN: current_state=menu_main(&game);break; case CUI_MENU_PLAY: current_state=menu_play(&game);break; case CUI_MENU_OPTION:current_state=menu_option(&game);break; case CUI_MENU_OPTION_GENERAL:current_state=menu_option_general(&game);break; case CUI_MENU_OPTION_GFX:current_state=menu_option_gfx(&game);break; case CUI_MENU_OPTION_SND:current_state=menu_option_snd(&game);break; case CUI_MENU_CREDITS:current_state=menu_credits(&game);break; case CUI_MENU_PAUSE:current_state=menu_pause(&game);break; case CUI_MENU_HOME:current_state=menu_home(&game);break; case CUI_MENU_EXIT:current_state=menu_exit(&game);break; default:break; } } GRRLIB_FreeTexture(tex_wallpaper); GRRLIB_FreeTexture(cursor.tex[0]); GRRLIB_FreeTexture(cursor.tex[1]); GRRLIB_Exit(); return 0; }