/*---------------------------------------------------------------------------* Project: THP Player File: main.c Copyright (C) 2002-2006 Nintendo. All Rights Reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: main.c,v $ Revision 1.4 2008/05/30 12:00:33 aka Added switch of stereo <-> mono. Revision 1.3 2006/10/11 02:52:02 aka Revised HOLLYWOOD_REV. Revision 1.2 2006/03/06 09:59:05 kawaset Eliminated warnings. Revision 1.1 2006/02/03 10:01:41 aka Imported from Dolphin tree. 4 2003/11/25 11:24 Dante Japanese to English translation of comments and text strings 3 2002/05/14 9:08a Suzuki supported multi audio track 2 2002/02/28 6:36p Akagi enabled to use with MusyX/AX by Suzuki-san (IRD). 1 2002/01/16 10:52a Akagi Initial revision made by Suzuki-san (IRD). $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include "axseq.h" #include "THPPlayer.h" static void MovieDoneRender(void); MEMHeapHandle __ExpHeap; void main(void) { u32 size, x, y; u8 *buffer; GXRenderModeObj *rmode; GXColor black; THPVideoInfo videoInfo; THPAudioInfo audioInfo; s32 frame, vol, audioTrack, smode; u16 buttonDown, button, dir; char *fileName; BOOL open, play, onMemory; void *arenaMem2Lo; void *arenaMem2Hi; black.r = 0; black.g = 0; black.b = 0; black.a = 255; DEMOInit(&GXNtsc480Int); arenaMem2Lo = OSGetMEM2ArenaLo(); arenaMem2Hi = OSGetMEM2ArenaHi(); __ExpHeap = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo); GXSetDispCopyGamma(GX_GM_1_0); GXSetCopyFilter(FALSE, NULL, FALSE, NULL); GXSetCopyClear(black, 0xffffff); rmode = DEMOGetRenderModeObj(); AIInit(NULL); AXSeqSetup(); THPPlayerInit(THP_MODE_WITH_AX); open = FALSE; play = FALSE; onMemory = FALSE; OSReport("\n"); OSReport("###########################################################\n"); OSReport("Push A Button : Play the movie with audio\n"); OSReport("Push B Button : Play the movie with audio on the memory\n"); OSReport("Push X Button : Play the interlace movie\n"); OSReport("Push Y Button : Play the movie with multiple audio track,\n"); OSReport(" : select audio track at random\n"); OSReport("Push L Trigger : Pause / Restart the movie\n"); OSReport("Push R Trigger : Skip one frame if the movie is paused\n"); OSReport("Pad Up : Volume up\n"); OSReport("Pad Down : Volume down\n"); OSReport("Pad Right : Play/stop midi file using AX\n"); OSReport("Push Start Button : Application end\n"); OSReport("###########################################################\n"); while(1) { DEMOPadRead(); buttonDown = DEMOPadGetButtonDown(PAD_CHAN0); button = DEMOPadGetButton(PAD_CHAN0); dir = DEMOPadGetDirs(PAD_CHAN0); DEMOBeforeRender(); if (play) { frame = THPPlayerDrawCurrentFrame(rmode, x, y, videoInfo.xSize, videoInfo.ySize); } // Movie Playback DoneRender MovieDoneRender(); // Check player state if (THPPlayerGetState() == THP_PLAYER_ERROR) { THPPlayerStop(); THPPlayerClose(); MEMFreeToExpHeap(__ExpHeap, buffer); OSHalt("Error happen"); } if (buttonDown & PAD_BUTTON_A) { fileName = "thpdemo/rebirth.thp"; open = TRUE; onMemory = FALSE; } if (buttonDown & PAD_BUTTON_B) { fileName = "thpdemo/fish.thp"; open = TRUE; onMemory = TRUE; } if (buttonDown & PAD_BUTTON_X) { fileName = "thpdemo/fish_int.thp"; open = TRUE; onMemory = FALSE; } if (buttonDown & PAD_BUTTON_Y) { fileName = "thpdemo/fish_mlt.thp"; open = TRUE; onMemory = FALSE; } if (buttonDown & PAD_TRIGGER_L) { if (THPPlayerGetState() == THP_PLAYER_PAUSE) { THPPlayerPlay(); } else { THPPlayerPause(); } } if (buttonDown & PAD_TRIGGER_R) { THPPlayerSkip(); } if (buttonDown & PAD_BUTTON_START) { if (play) { THPPlayerStop(); THPPlayerClose(); MEMFreeToExpHeap(__ExpHeap, buffer); } break; } if (button & PAD_BUTTON_UP) { vol = THPPlayerGetVolume() + 1; if (vol > 127) { vol = 127; } THPPlayerSetVolume(vol, 0); } if (button & PAD_BUTTON_DOWN) { vol = THPPlayerGetVolume() - 1; if (vol < 0) { vol = 0; } THPPlayerSetVolume(vol, 0); } if (buttonDown & PAD_BUTTON_RIGHT) { if (GetSeqState()) { SeqStop(); } else { SeqPlay(); } } if (buttonDown & PAD_TRIGGER_Z) { smode = THPPlayerGetSoundMode(); if (smode == THP_SOUND_MODE_MONO) { THPPlayerSetSoundMode(THP_SOUND_MODE_STEREO); OSReport("Change sound mode : mono -> stereo.\n"); } else if (smode == THP_SOUND_MODE_STEREO) { THPPlayerSetSoundMode(THP_SOUND_MODE_MONO); OSReport("Change sound mode : stereo -> mono.\n"); } else { OSReport("Change sound mode : ???.\n"); } } if (open) { // If playing back, release Stop and work area if (play) { THPPlayerStop(); THPPlayerClose(); MEMFreeToExpHeap(__ExpHeap, buffer); play = FALSE; } } if (open && !play) { // Open THP file if (THPPlayerOpen(fileName, onMemory) == FALSE) { OSHalt("Fail to open the thp file\n"); } THPPlayerGetVideoInfo(&videoInfo); THPPlayerGetAudioInfo(&audioInfo); x = (rmode->fbWidth - videoInfo.xSize) / 2; y = (rmode->efbHeight - videoInfo.ySize) / 2; // Set aside work area size = THPPlayerCalcNeedMemory(); buffer = MEMAllocFromExpHeapEx(__ExpHeap, size, 32); if (!buffer) { OSHalt("Can't allocate the memory"); } // Set work area THPPlayerSetBuffer(buffer); // Select randomly, if there are multiple audio tracks. if (audioInfo.sndNumTracks != 1) { audioTrack = (s32)(OSGetTick() % audioInfo.sndNumTracks); } else { audioTrack = 0; } // Preparation before playback if (THPPlayerPrepare(0, THP_PLAY_LOOP, audioTrack) == FALSE) { OSHalt("Fail to prepare\n"); } // Start playback THPPlayerPlay(); open = FALSE; play = TRUE; } } THPPlayerQuit(); VIWaitForRetrace(); OSHalt("application end\n"); return; } static void MovieDoneRender(void) { // Release used THP video data at same time as graphics processor THPPlayerDrawDone(); DEMODoneRender(); }