/*---------------------------------------------------------------------------* 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.2 06/08/2006 06:11:30 aka Removed setting of tempDisableFX for new AXFX. Revision 1.1 02/03/2006 10:01:27 aka Imported from Dolphin tree. 2 03/11/25 11:24 Dante Japanese to English translation of comments and text strings 1 02/05/14 11:28a Suzuki Initial check-in. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #ifdef HOLLYWOOD_REV #include #endif #include "THPPlayerStrmAX.h" static void MovieDoneRender(void); static void CallbackAudioFrame(void); static void AXSetup(void); static AXFX_REVERBHI RevH; #ifndef HOLLYWOOD_REV #define MAX_ARAM_BLOCKS 10 static u32 AramMemArray[MAX_ARAM_BLOCKS]; #endif void main(void) { u32 size, x, y; u8 *buffer; GXRenderModeObj *rmode; GXColor black; THPVideoInfo videoInfo; THPAudioInfo audioInfo; s32 frame, audioTrack; u16 buttonDown, dir; char *fileName; BOOL open, play, onMemory; AXVPB *left, *right; #ifndef HOLLYWOOD_REV u32 aramSize, aramAddr; #else void *arenaMem2Lo; void *arenaMem2Hi; MEMHeapHandle ExpHeap; #endif black.r = 0; black.g = 0; black.b = 0; black.a = 255; DEMOInit(&GXNtsc480Int); #ifndef HOLLYWOOD_REV ARInit(AramMemArray, MAX_ARAM_BLOCKS); ARQInit(); #else arenaMem2Lo = OSGetMEM2ArenaLo(); arenaMem2Hi = OSGetMEM2ArenaHi(); ExpHeap = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo); #endif AIInit(NULL); AXSetup(); GXSetDispCopyGamma(GX_GM_1_0); GXSetCopyFilter(FALSE, NULL, FALSE, NULL); GXSetCopyClear(black, 0xffffff); rmode = DEMOGetRenderModeObj(); THPPlayerInit(); 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 interlaced 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("Push Start Button : Application end\n"); OSReport("###########################################################\n"); while(1) { DEMOPadRead(); buttonDown = DEMOPadGetButtonDown(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(); #ifndef HOLLYWOOD_REV OSFree(buffer); #else MEMFreeToExpHeap(ExpHeap, buffer); #endif 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(); #ifndef HOLLYWOOD_REV OSFree(buffer); ARFree(&aramSize); #else MEMFreeToExpHeap(ExpHeap, buffer); #endif } break; } if (dir & DEMO_STICK_RIGHT) { THPPlayerSkip(); } if (open) { // If playing back, release Stop and work area if (play) { THPPlayerStop(); THPPlayerClose(); #ifndef HOLLYWOOD_REV OSFree(buffer); ARFree(&aramSize); #else MEMFreeToExpHeap(ExpHeap, buffer); #endif play = FALSE; } } if (open && !play) { // Open THP file if (THPPlayerOpen(fileName, onMemory) == FALSE) { OSHalt("Failed 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(); #ifndef HOLLYWOOD_REV buffer = (u8 *)OSAlloc(size); #else buffer = MEMAllocFromExpHeapEx(ExpHeap, size, 32); #endif if (!buffer) { OSHalt("Cannot allocate the memory"); } // Set work area THPPlayerSetBuffer(buffer); #ifndef HOLLYWOOD_REV // Calculate A Memory which is necessary for Audio Streaming aramSize = THPPlayerCalcNeedAmemory(); // Keep A Memory aramAddr = ARAlloc(aramSize); // Set A Memory THPPlayerSetAmemory(aramAddr); #endif // 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("Failed to prepare\n"); } THPPlayerGetStreamAXPB(&left, &right); if (left) { MIXSetInput(left, 0); MIXAuxAPreFader(left); MIXSetFader(left, -904); MIXSetAuxA(left, 0); } if (right) { MIXSetInput(right, 0); MIXAuxAPreFader(right); MIXSetFader(right, -904); MIXSetAuxA(right, 0); } // 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(); } static void CallbackAudioFrame(void) { BOOL old; old = OSEnableInterrupts(); MIXUpdateSettings(); THPPlayerStreamUpdate(); OSRestoreInterrupts(old); } static void AXSetup(void) { AXInit(); MIXInit(); AXRegisterCallback(CallbackAudioFrame); RevH.time = 3.0f; RevH.preDelay = 0.1f; RevH.damping = 0.6f; RevH.coloration = 0.9f; RevH.crosstalk = 0.0f; RevH.mix = 0.65f; AXFXReverbHiInit(&RevH); AXRegisterAuxACallback((void *)&AXFXReverbHiCallback, (void*)&RevH); }