1 /*---------------------------------------------------------------------------*
2 Project: THP Player
3 File: main.c
4
5 Copyright (C)2002-2006 Nintendo All Rights Reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: main.c,v $
14 Revision 1.2 06/08/2006 06:11:30 aka
15 Removed setting of tempDisableFX for new AXFX.
16
17 Revision 1.1 02/03/2006 10:01:27 aka
18 Imported from Dolphin tree.
19
20
21 2 03/11/25 11:24 Dante
22 Japanese to English translation of comments and text strings
23
24 1 02/05/14 11:28a Suzuki
25 Initial check-in.
26
27 $NoKeywords: $
28
29 *---------------------------------------------------------------------------*/
30
31 #include <demo.h>
32 #include <revolution/axfx.h>
33 #include <revolution/mix.h>
34 #ifdef HOLLYWOOD_REV
35 #include <revolution/mem.h>
36 #endif
37
38 #include "THPPlayerStrmAX.h"
39
40 static void MovieDoneRender(void);
41 static void CallbackAudioFrame(void);
42 static void AXSetup(void);
43
44 static AXFX_REVERBHI RevH;
45
46 #ifndef HOLLYWOOD_REV
47 #define MAX_ARAM_BLOCKS 10
48 static u32 AramMemArray[MAX_ARAM_BLOCKS];
49 #endif
50
main(void)51 void main(void)
52 {
53 u32 size, x, y;
54 u8 *buffer;
55 GXRenderModeObj *rmode;
56 GXColor black;
57 THPVideoInfo videoInfo;
58 THPAudioInfo audioInfo;
59 s32 frame, audioTrack;
60 u16 buttonDown, dir;
61 char *fileName;
62 BOOL open, play, onMemory;
63 AXVPB *left, *right;
64 #ifndef HOLLYWOOD_REV
65 u32 aramSize, aramAddr;
66 #else
67 void *arenaMem2Lo;
68 void *arenaMem2Hi;
69 MEMHeapHandle ExpHeap;
70 #endif
71
72 black.r = 0;
73 black.g = 0;
74 black.b = 0;
75 black.a = 255;
76
77 DEMOInit(&GXNtsc480Int);
78
79 #ifndef HOLLYWOOD_REV
80 ARInit(AramMemArray, MAX_ARAM_BLOCKS);
81 ARQInit();
82 #else
83 arenaMem2Lo = OSGetMEM2ArenaLo();
84 arenaMem2Hi = OSGetMEM2ArenaHi();
85 ExpHeap = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo);
86 #endif
87
88 AIInit(NULL);
89
90 AXSetup();
91
92 GXSetDispCopyGamma(GX_GM_1_0);
93 GXSetCopyFilter(FALSE, NULL, FALSE, NULL);
94 GXSetCopyClear(black, 0xffffff);
95
96 rmode = DEMOGetRenderModeObj();
97
98 THPPlayerInit();
99
100 open = FALSE;
101 play = FALSE;
102 onMemory = FALSE;
103
104 OSReport("\n");
105 OSReport("###########################################################\n");
106 OSReport("Push A Button : Play the movie with audio\n");
107 OSReport("Push B Button : Play the movie with audio on the memory\n");
108 OSReport("Push X Button : Play the interlaced movie\n");
109 OSReport("Push Y Button : Play the movie with multiple audio track,\n");
110 OSReport(" : select audio track at random\n");
111 OSReport("Push L Trigger : Pause / Restart the movie\n");
112 OSReport("Push R Trigger : Skip one frame if the movie is paused\n");
113 OSReport("Push Start Button : Application end\n");
114 OSReport("###########################################################\n");
115
116 while(1)
117 {
118 DEMOPadRead();
119
120 buttonDown = DEMOPadGetButtonDown(PAD_CHAN0);
121 dir = DEMOPadGetDirs(PAD_CHAN0);
122
123 DEMOBeforeRender();
124
125 if (play)
126 {
127 frame = THPPlayerDrawCurrentFrame(rmode, x, y, videoInfo.xSize, videoInfo.ySize);
128 }
129
130 // Movie Playback DoneRender
131 MovieDoneRender();
132
133 // Check player state
134 if (THPPlayerGetState() == THP_PLAYER_ERROR)
135 {
136 THPPlayerStop();
137 THPPlayerClose();
138 #ifndef HOLLYWOOD_REV
139 OSFree(buffer);
140 #else
141 MEMFreeToExpHeap(ExpHeap, buffer);
142 #endif
143 OSHalt("Error happen");
144 }
145
146 if (buttonDown & PAD_BUTTON_A)
147 {
148 fileName = "thpdemo/rebirth.thp";
149 open = TRUE;
150 onMemory = FALSE;
151 }
152
153 if (buttonDown & PAD_BUTTON_B)
154 {
155 fileName = "thpdemo/fish.thp";
156 open = TRUE;
157 onMemory = TRUE;
158 }
159
160 if (buttonDown & PAD_BUTTON_X)
161 {
162 fileName = "thpdemo/fish_int.thp";
163 open = TRUE;
164 onMemory = FALSE;
165 }
166
167 if (buttonDown & PAD_BUTTON_Y)
168 {
169 fileName = "thpdemo/fish_mlt.thp";
170 open = TRUE;
171 onMemory = FALSE;
172 }
173
174 if (buttonDown & PAD_TRIGGER_L)
175 {
176 if (THPPlayerGetState() == THP_PLAYER_PAUSE)
177 {
178 THPPlayerPlay();
179 }
180 else
181 {
182 THPPlayerPause();
183 }
184 }
185
186 if (buttonDown & PAD_TRIGGER_R)
187 {
188 THPPlayerSkip();
189 }
190
191 if (buttonDown & PAD_BUTTON_START)
192 {
193 if (play)
194 {
195 THPPlayerStop();
196 THPPlayerClose();
197 #ifndef HOLLYWOOD_REV
198 OSFree(buffer);
199 ARFree(&aramSize);
200 #else
201 MEMFreeToExpHeap(ExpHeap, buffer);
202 #endif
203 }
204
205 break;
206 }
207
208 if (dir & DEMO_STICK_RIGHT)
209 {
210 THPPlayerSkip();
211 }
212
213 if (open)
214 {
215 // If playing back, release Stop and work area
216 if (play)
217 {
218 THPPlayerStop();
219 THPPlayerClose();
220 #ifndef HOLLYWOOD_REV
221 OSFree(buffer);
222 ARFree(&aramSize);
223 #else
224 MEMFreeToExpHeap(ExpHeap, buffer);
225 #endif
226 play = FALSE;
227 }
228 }
229
230 if (open && !play)
231 {
232 // Open THP file
233 if (THPPlayerOpen(fileName, onMemory) == FALSE)
234 {
235 OSHalt("Failed to open the THP file\n");
236 }
237
238 THPPlayerGetVideoInfo(&videoInfo);
239 THPPlayerGetAudioInfo(&audioInfo);
240
241 x = (rmode->fbWidth - videoInfo.xSize) / 2;
242 y = (rmode->efbHeight - videoInfo.ySize) / 2;
243
244 // Set aside work area
245 size = THPPlayerCalcNeedMemory();
246
247 #ifndef HOLLYWOOD_REV
248 buffer = (u8 *)OSAlloc(size);
249 #else
250 buffer = MEMAllocFromExpHeapEx(ExpHeap, size, 32);
251 #endif
252
253 if (!buffer)
254 {
255 OSHalt("Cannot allocate the memory");
256 }
257
258 // Set work area
259 THPPlayerSetBuffer(buffer);
260
261 #ifndef HOLLYWOOD_REV
262 // Calculate A Memory which is necessary for Audio Streaming
263 aramSize = THPPlayerCalcNeedAmemory();
264
265 // Keep A Memory
266 aramAddr = ARAlloc(aramSize);
267
268 // Set A Memory
269 THPPlayerSetAmemory(aramAddr);
270 #endif
271
272 // Select randomly, if there are multiple audio tracks.
273 if (audioInfo.sndNumTracks != 1)
274 {
275 audioTrack = (s32)(OSGetTick() % audioInfo.sndNumTracks);
276 }
277 else
278 {
279 audioTrack = 0;
280 }
281
282 // Preparation before playback
283 if (THPPlayerPrepare(0, THP_PLAY_LOOP, audioTrack) == FALSE)
284 {
285 OSHalt("Failed to prepare\n");
286 }
287
288 THPPlayerGetStreamAXPB(&left, &right);
289
290 if (left)
291 {
292 MIXSetInput(left, 0);
293 MIXAuxAPreFader(left);
294 MIXSetFader(left, -904);
295 MIXSetAuxA(left, 0);
296 }
297
298 if (right)
299 {
300 MIXSetInput(right, 0);
301 MIXAuxAPreFader(right);
302 MIXSetFader(right, -904);
303 MIXSetAuxA(right, 0);
304 }
305
306 // Start playback
307 THPPlayerPlay();
308
309 open = FALSE;
310 play = TRUE;
311 }
312 }
313
314 THPPlayerQuit();
315
316 VIWaitForRetrace();
317
318 OSHalt("application end\n");
319
320 return;
321 }
322
MovieDoneRender(void)323 static void MovieDoneRender(void)
324 {
325 // Release used THP video data at same time as graphics processor
326 THPPlayerDrawDone();
327
328 DEMODoneRender();
329 }
330
CallbackAudioFrame(void)331 static void CallbackAudioFrame(void)
332 {
333 BOOL old;
334
335 old = OSEnableInterrupts();
336
337 MIXUpdateSettings();
338
339 THPPlayerStreamUpdate();
340
341 OSRestoreInterrupts(old);
342 }
343
AXSetup(void)344 static void AXSetup(void)
345 {
346 AXInit();
347 MIXInit();
348
349 AXRegisterCallback(CallbackAudioFrame);
350
351 RevH.time = 3.0f;
352 RevH.preDelay = 0.1f;
353 RevH.damping = 0.6f;
354 RevH.coloration = 0.9f;
355 RevH.crosstalk = 0.0f;
356 RevH.mix = 0.65f;
357
358 AXFXReverbHiInit(&RevH);
359
360 AXRegisterAuxACallback((void *)&AXFXReverbHiCallback, (void*)&RevH);
361 }
362