/*---------------------------------------------------------------------------* 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 2006/10/23 02:12:22 aka Changed from AXInit() to AXInitSpecifyMem(). Changed from MIXInit() to MIXInitSpecifyMem(). Revision 1.3 2006/10/11 02:50:45 aka Revised AXInit() and MIXInit(). Revision 1.2 2006/06/08 06:11:30 aka Removed setting of tempDisableFX for new AXFX. Revision 1.1 2006/02/03 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 checkin $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include "THPPlayerStrmAX.h" static void MovieDoneRender(void); static void CallbackAudioFrame(void); static void AXSetup(void); static AXFX_REVERBHI RevH; static MEMHeapHandle ExpHeap; 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; 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); 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(); 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 (dir & DEMO_STICK_RIGHT) { THPPlayerSkip(); } 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("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(); buffer = MEMAllocFromExpHeapEx(ExpHeap, size, 32); if (!buffer) { OSHalt("Cannot 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("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) { void *axBuffer; void *mixBuffer; axBuffer = MEMAllocFromExpHeapEx(ExpHeap, AXGetMemorySize(AX_MAX_VOICES), 32); mixBuffer = MEMAllocFromExpHeap(ExpHeap, MIXGetMemorySize(AX_MAX_VOICES)); AXInitSpecifyMem(AX_MAX_VOICES, axBuffer); // initialize AX MIXInitSpecifyMem(mixBuffer); // initialize mixer 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); }