1 /*---------------------------------------------------------------------------*
2   Project: Delay (expanded version : Dpl2 ) Test
3   File:    expdelayDpl2.c
4 
5   Copyright (C)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: expdelayDpl2.c,v $
14   Revision 1.6  2006/11/21 08:21:38  aka
15   Removed the zero buffer.
16 
17   Revision 1.5  2006/10/23 02:05:52  aka
18   Changed from AXInit() to AXInitSpecifyMem().
19   Changed from MIXInit() to MIXInitSpecifyMem().
20   Changed from SYNInit() to SYNInitSpecifyMem().
21 
22   Revision 1.4  2006/10/10 08:30:06  aka
23   Revised AXInit(), MIXInit() and SYNInit().
24 
25   Revision 1.3  2006/09/18 04:28:22  aka
26   Modified using AX_MAX_VOICES instead of MAX_DEMO_VOICES.
27 
28   Revision 1.2  2006/06/09 11:49:25  aka
29   Revised mode from SURROUND to DPL2.
30 
31   Revision 1.1  2006/06/08 08:16:15  aka
32   Imported new demos for new AXFX made by Kawamura-san (EAD).
33 
34   $NoKeywords: $
35  *---------------------------------------------------------------------------*/
36 
37 
38 /*---------------------------------------------------------------------------*
39  * Includes
40  *---------------------------------------------------------------------------*/
41 
42 #include <demo.h>
43 #include <demo/DEMOWin.h>
44 #include <revolution.h>
45 #include <revolution/mix.h>
46 #include <revolution/sp.h>
47 #include <revolution/axfx.h>
48 #include <revolution/axfx_presets.h>
49 #include <revolution/mem.h>
50 #include <string.h>
51 
52 #include "dpl2reverb.h"
53 
54 /*---------------------------------------------------------------------------*
55  * SP data
56  *---------------------------------------------------------------------------*/
57 
58 #define SPT_FILE "/axdemo/dpl2/dpl2reverb.spt"
59 #define SPD_FILE "/axdemo/dpl2/dpl2reverb.spd"
60 
61 // use only a single SP sound table
62 static SPSoundTable *sp_table;
63 static u8           *sp_data;
64 
65 /*---------------------------------------------------------------------------*
66  * Exp Heap
67  *---------------------------------------------------------------------------*/
68 static MEMHeapHandle hExpHeap;
69 
70 /*---------------------------------------------------------------------------*
71  * AX and Application-layer voice abstraction
72  *---------------------------------------------------------------------------*/
73 
74 // Checks SP entry 'type' to see if the voice is looped or not
75 #define mISLOOPED(x) ((x->type)&0x1)
76 
77 int panX;   // pan value for left/right
78 int panY;   // pan value for front/back
79 
80 // Each voice has an associated AX parameter block and an SP entry
81 typedef struct
82 {
83     AXVPB *ax_voice;
84     SPSoundEntry *sp_entry;
85 } DEMO_VOICE;
86 
87 DEMO_VOICE demo_voices[AX_MAX_VOICES];
88 
89 // Constructs for Aux-bus effects
90 static AXFX_DELAY_EXP_DPL2       delay;
91 
92 // AX profiling structures
93 
94 // store up to 8 frames, just to be safe
95 #define NUM_AX_PROFILE_FRAMES 8
96 
97 static AXPROFILE        ax_profile[NUM_AX_PROFILE_FRAMES];
98 
99 /*---------------------------------------------------------------------------*
100  * Prototypes
101  *---------------------------------------------------------------------------*/
102 
103 // for AX and voice abstraction layer
104 static void         ax_demo_callback        (void);
105 static void         ax_drop_voice_callback  (void *p);
106 static void         stop_all_voices         (void);
107 static void         stop_voice              (DEMO_VOICE *v);
108 static DEMO_VOICE  *play_sfx                (u32 sfx);
109 
110 // for UI menus
111 static void         MNU_sound               (DEMOWinMenuInfo *menu, u32 item, u32 *result);
112 static void         MNU_position            (DEMOWinMenuInfo *menu, u32 item, u32 *result);
113 static void         MNU_stop_sfx            (DEMOWinMenuInfo *menu, u32 item, u32 *result);
114 static void         MNU_auxa                (DEMOWinMenuInfo *menu, u32 item, u32 *result);
115 static void         MNU_compressor          (DEMOWinMenuInfo *menu, u32 item, u32 *result);
116 static void         MNU_kill_all            (DEMOWinMenuInfo *menu, u32 item, u32 *result);
117 
118 /*---------------------------------------------------------------------------*
119  * User Interface stuff
120  *---------------------------------------------------------------------------*/
121 
122 static u32 soundIndex    = 0;   // current sound effect to play
123 static u32 positionIndex = 0;   // current panning
124 static u32 auxaIndex     = 0;   // current effect to apply to AuxA bus
125 static u32 compressFlag  = 0;   // current compressor state
126 
127 DEMOWinInfo *DebugWin;
128 DEMOWinInfo *PositionWin;
129 
130 DEMOWinMenuItem MenuItem[] =
131 {
132     { "Sound   : (none)",            DEMOWIN_ITM_NONE,       MNU_sound,        NULL },
133     { "AuxA    : (none)",            DEMOWIN_ITM_NONE,       MNU_auxa,         NULL },
134     { "",                            DEMOWIN_ITM_SEPARATOR,  NULL,             NULL },
135     { "Position: C Stick",           DEMOWIN_ITM_NONE,       MNU_position,     NULL },
136     { "",                            DEMOWIN_ITM_SEPARATOR,  NULL,             NULL },
137     { "Compress: No",                DEMOWIN_ITM_NONE,       MNU_compressor,   NULL },
138     { "",                            DEMOWIN_ITM_SEPARATOR,  NULL,             NULL },
139     { "Kill All Voices",             DEMOWIN_ITM_NONE,       MNU_kill_all,     NULL },
140     { "",                            DEMOWIN_ITM_TERMINATOR, NULL,             NULL }
141 
142 };
143 
144 DEMOWinMenuInfo Menu =
145 {
146     "AX DelayExpDpl2 Test",     // title
147     NULL,                       // window handle
148     MenuItem,                   // list of menu items
149      9,                         // max num of items to display at a time
150     DEMOWIN_MNU_NONE,           // attribute flags
151 
152     // user callbacks
153     NULL,                       // callback for menu open event
154     NULL,                       // callback for cursor move event
155     NULL,                       // callback for item select event
156     NULL,                       // callback for cancel event
157 
158     // private members
159     0, 0, 0, 0, 0
160 };
161 
162 DEMOWinMenuInfo *MenuPtr;
163 
164 /*===========================================================================*
165  *                   F U N C T I O N    D E F I N I T I O N S
166  *===========================================================================*/
167 
168 
169 /*---------------------------------------------------------------------------*
170  * VOICE ABSTRACTION LAYER STUFF
171 /*---------------------------------------------------------------------------*
172 
173 
174 /*---------------------------------------------------------------------------*
175  * Name        :
176  * Description :
177  * Arguments   :
178  * Returns     :
179  *---------------------------------------------------------------------------*/
180 
181 
stop_voice(DEMO_VOICE * v)182 static void stop_voice(DEMO_VOICE *v)
183 {
184 
185     u32  i;
186     BOOL old;
187 
188         old = OSDisableInterrupts();
189 
190         for (i=0; i<AX_MAX_VOICES; i++)
191         {
192             if (v == &demo_voices[i])
193             {
194                 if (demo_voices[i].ax_voice)
195                 {
196                     if (mISLOOPED(demo_voices[i].sp_entry))
197                     {
198                         SPPrepareEnd(demo_voices[i].sp_entry, demo_voices[i].ax_voice);
199                     }
200                     else
201                     {
202                         AXSetVoiceState(demo_voices[i].ax_voice, AX_PB_STATE_STOP);
203                     }
204 
205                     break;
206                 }
207 
208             }
209         }
210 
211         (void)OSRestoreInterrupts(old);
212 
213 
214 } // end stop_voice()
215 
216 /*---------------------------------------------------------------------------*
217  * Name        :
218  * Description :
219  * Arguments   :
220  * Returns     :
221  *---------------------------------------------------------------------------*/
222 
stop_all_voices(void)223 static void stop_all_voices(void)
224 {
225 
226     u32  i;
227     BOOL old;
228 
229 
230 
231         old = OSDisableInterrupts();
232 
233         for (i=0; i<AX_MAX_VOICES; i++)
234         {
235             if (demo_voices[i].ax_voice)
236             {
237                 if (mISLOOPED(demo_voices[i].sp_entry))
238                 {
239                     SPPrepareEnd(demo_voices[i].sp_entry, demo_voices[i].ax_voice);
240                 }
241                 else
242                 {
243                     AXSetVoiceState(demo_voices[i].ax_voice, AX_PB_STATE_STOP);
244                 }
245 
246             }
247 
248         }
249 
250         (void)OSRestoreInterrupts(old);
251 
252 
253 } // end stop_voice()
254 
255 /*---------------------------------------------------------------------------*
256  * Name        :
257  * Description :
258  * Arguments   :
259  * Returns     :
260  *---------------------------------------------------------------------------*/
261 
262 
play_sfx(u32 sfx)263 static DEMO_VOICE *play_sfx(u32 sfx)
264 {
265 
266     AXVPB      *ax_v;
267     DEMO_VOICE *v;
268 
269     BOOL        old;
270 
271 
272         old = OSDisableInterrupts();
273 
274         ax_v = AXAcquireVoice(15, ax_drop_voice_callback, 0);
275 
276         if (ax_v)
277         {
278             // use AX voice index to reference a voice in the demo abstraction layer
279             demo_voices[ax_v->index].ax_voice = ax_v;
280 
281             // assign a pointer for convenience
282             v = &demo_voices[ax_v->index];
283 
284             // grab the requested sound from the SP table
285             v->sp_entry = SPGetSoundEntry(sp_table, sfx);
286 
287             SPPrepareSound(v->sp_entry, v->ax_voice, (v->sp_entry)->sampleRate);
288 
289 
290             MIXInitChannel(v->ax_voice, 0, 0, 0, -960, -960, panX, 127-panY, 0);
291             AXSetVoiceState(v->ax_voice, AX_PB_STATE_RUN);
292 
293             (void)OSRestoreInterrupts(old);
294         }
295         else
296         {
297             v = NULL;
298             (void)OSRestoreInterrupts(old);
299             DEMOWinLogPrintf(DebugWin, "ERROR: AX voice allocation failed.\n");
300 
301         }
302 
303         return(v);
304 
305 } // end play_sfx()
306 
307 
308 /*---------------------------------------------------------------------------*
309  * Name        :
310  * Description :
311  * Arguments   : None.
312  * Returns     : None.
313  *---------------------------------------------------------------------------*/
ax_demo_callback(void)314 static void ax_demo_callback(void)
315 {
316 
317     u32 i;
318 
319         // check for voices which have stopped and remove them from the
320         // abstraction layer
321         for (i=0; i<AX_MAX_VOICES; i++)
322         {
323             if (demo_voices[i].ax_voice)
324             {
325                 if ( AX_PB_STATE_STOP == ((demo_voices[i].ax_voice)->pb.state))
326                 {
327                     // if the voice has stopped, clear it from the abstraction layer
328                     MIXReleaseChannel(demo_voices[i].ax_voice);
329                     AXFreeVoice(demo_voices[i].ax_voice);
330                     demo_voices[i].ax_voice = NULL;
331                 }
332                 else
333                 {
334                     // otherwise, update the panning
335                     MIXSetPan(demo_voices[i].ax_voice, panX);
336                     MIXSetSPan(demo_voices[i].ax_voice, 127 - panY);
337                     MIXUpdateSettings();
338                 }
339             }
340         }
341 
342 } // end ax_demo_callback()
343 
344 
345 /*---------------------------------------------------------------------------*
346  * Name        : ax_drop_voice_callback()
347  * Description : Invoked by AX when a voice has been forciby dropped.
348  *               Must delete references to the voice from our abstraction layer
349  *               and release the associated MIXer channel.
350  * Arguments   : None.
351  * Returns     : None.
352  *---------------------------------------------------------------------------*/
ax_drop_voice_callback(void * p)353 static void ax_drop_voice_callback(void *p)
354 {
355 
356     AXVPB *v;
357 
358         v = (AXVPB *)p;
359 
360         MIXReleaseChannel(demo_voices[v->index].ax_voice);
361         demo_voices[v->index].ax_voice = NULL;
362         demo_voices[v->index].sp_entry = NULL;
363 
364 } // end ax_demo_callback()
365 
366 
367 
368 /*---------------------------------------------------------------------------*
369  * MENU FUNCTIONS
370 /*---------------------------------------------------------------------------*
371 
372 /*---------------------------------------------------------------------------*
373  * Name        :
374  * Description :
375  * Arguments   :
376  * Returns     :
377  *---------------------------------------------------------------------------*/
378 
MNU_compressor(DEMOWinMenuInfo * menu,u32 item,u32 * result)379 static void MNU_compressor(DEMOWinMenuInfo *menu, u32 item, u32 *result)
380 {
381 #pragma unused(menu, item, result)
382 
383     BOOL old;
384 
385         old = OSDisableInterrupts();
386 
387         compressFlag ^= 1;
388         AXSetCompressor(compressFlag);
389 
390         (void)OSRestoreInterrupts(old);
391 
392         if (compressFlag)
393         {
394             menu->items[item].name = "Compress: YES";
395         }
396         else
397         {
398             menu->items[item].name = "Compress: NO ";
399         }
400 
401 
402 } // end MNU_compressor()
403 
404 /*---------------------------------------------------------------------------*
405  * Name        :
406  * Description :
407  * Arguments   :
408  * Returns     :
409  *---------------------------------------------------------------------------*/
410 
MNU_kill_all(DEMOWinMenuInfo * menu,u32 item,u32 * result)411 static void MNU_kill_all(DEMOWinMenuInfo *menu, u32 item, u32 *result)
412 {
413 #pragma unused(menu, item, result)
414 
415 
416     u32  i;
417     BOOL old;
418 
419         old = OSDisableInterrupts();
420 
421         for (i=0; i<AX_MAX_VOICES; i++)
422         {
423             if (demo_voices[i].ax_voice)
424             {
425                 AXSetVoiceState(demo_voices[i].ax_voice, AX_PB_STATE_STOP);
426             }
427         }
428 
429         (void)OSRestoreInterrupts(old);
430 
431 
432 } // end MNU_kill_all()
433 
434 
435 
436 /*---------------------------------------------------------------------------*
437  * Name        :
438  * Description :
439  * Arguments   :
440  * Returns     :
441  *---------------------------------------------------------------------------*/
442 
MNU_auxa(DEMOWinMenuInfo * menu,u32 item,u32 * result)443 static void MNU_auxa(DEMOWinMenuInfo *menu, u32 item, u32 *result)
444 {
445 #pragma unused(menu, item, result)
446 
447     auxaIndex++;
448 
449     auxaIndex %= 5;
450 
451     switch (auxaIndex)
452     {
453         case 0:
454             AXFXDelayExpShutdownDpl2(&delay);
455             AXRegisterAuxACallback(NULL, NULL);
456             menu->items[item].name = "Delay : (none)";
457             break;
458         case 1:
459             AXFX_PRESET_DELAY_EXP_TYPE1(&delay);
460             AXFXDelayExpSettingsDpl2(&delay);
461             AXRegisterAuxACallback((void*)&AXFXDelayExpCallbackDpl2, (void*)&delay);
462             menu->items[item].name = "Delay : Type 1";
463             break;
464 
465 
466         case 2:
467             AXFX_PRESET_DELAY_EXP_TYPE2(&delay);
468             AXFXDelayExpSettingsDpl2(&delay);
469             AXRegisterAuxACallback((void*)&AXFXDelayExpCallbackDpl2, (void*)&delay);
470             menu->items[item].name = "Delay : Type 2";
471             break;
472 
473         case 3:
474             AXFX_PRESET_DELAY_EXP_FLANGE1(&delay);
475             AXFXDelayExpSettingsDpl2(&delay);
476             AXRegisterAuxACallback((void*)&AXFXDelayExpCallbackDpl2, (void*)&delay);
477             menu->items[item].name = "Delay : Flange 1";
478             break;
479 
480         case 4:
481             AXFX_PRESET_DELAY_EXP_FLANGE2(&delay);
482             AXFXDelayExpSettingsDpl2(&delay);
483             AXRegisterAuxACallback((void*)&AXFXDelayExpCallbackDpl2, (void*)&delay);
484             menu->items[item].name = "Delay : Flange 2";
485             break;
486 
487 
488     }
489 
490 
491 } // end MNU_auxa()
492 
493 
494 /*---------------------------------------------------------------------------*
495  * Name        :
496  * Description :
497  * Arguments   :
498  * Returns     :
499  *---------------------------------------------------------------------------*/
500 
MNU_sound(DEMOWinMenuInfo * menu,u32 item,u32 * result)501 static void MNU_sound(DEMOWinMenuInfo *menu, u32 item, u32 *result)
502 {
503 #pragma unused(result)
504 
505         soundIndex++;
506         soundIndex %= 5;
507 
508 
509         stop_all_voices();
510 
511         switch (soundIndex)
512         {
513             case 0: // None
514 
515                 menu->items[item].name = "Sound   : None";
516                 break;
517 
518             case 1:
519 
520                 play_sfx(SFX_TICK);
521                 menu->items[item].name = "Sound   : TICK";
522 
523                 break;
524 
525             case 2:
526 
527                 play_sfx(SFX_EXPLODE);
528                 menu->items[item].name = "Sound   : EXPLOSION";
529 
530                 break;
531 
532             case 3:
533 
534                 play_sfx(SFX_MACHINEGUN);
535                 menu->items[item].name = "Sound   : MACHINEGUN";
536 
537                 break;
538 
539             case 4:
540 
541                 play_sfx(SFX_SYNTH);
542                 menu->items[item].name = "Sound   : SYNTH";
543 
544                 break;
545 
546         } // end switch()
547 
548 } // end MNU_sound
549 
550 
551 
552 
553 
554 /*---------------------------------------------------------------------------*
555  * Name        :
556  * Description :
557  * Arguments   :
558  * Returns     :
559  *---------------------------------------------------------------------------*/
560 
MNU_position(DEMOWinMenuInfo * menu,u32 item,u32 * result)561 static void MNU_position(DEMOWinMenuInfo *menu, u32 item, u32 *result)
562 {
563 #pragma unused(result)
564 
565         positionIndex++;
566         positionIndex %= 7;
567 
568         switch (positionIndex)
569         {
570             case 0:
571 
572                 menu->items[item].name = "Position: C Stick";
573 
574                 break;
575 
576             case 1:
577 
578                 panX = 0;
579                 panY = 0;
580                 menu->items[item].name = "Position: L";
581 
582                 break;
583 
584             case 2:
585 
586                 panX = 63;
587                 panY = 0;
588                 menu->items[item].name = "Position: C";
589 
590                 break;
591 
592             case 3:
593 
594                 panX = 127;
595                 panY = 0;
596                 menu->items[item].name = "Position: R";
597 
598                 break;
599 
600             case 4:
601 
602                 panX = 0;
603                 panY = 127;
604                 menu->items[item].name = "Position: Ls";
605 
606                 break;
607 
608             case 5:
609 
610                 panX = 127;
611                 panY = 127;
612                 menu->items[item].name = "Position: Rs";
613 
614                 break;
615 
616             case 6:
617 
618                 panX = 63;
619                 panY = 127;
620                 menu->items[item].name = "Position: Bs";
621 
622                 break;
623 
624             }
625 
626 } // end MNU_position()
627 
628 
629 /*---------------------------------------------------------------------------*
630  * Name        : position_win_update()
631  * Description : refresh callback for position window
632  * Arguments   :
633  * Returns     :
634  *---------------------------------------------------------------------------*/
635 
position_win_update(DEMOWinInfo * window)636 static void position_win_update(DEMOWinInfo *window)
637 {
638 
639 
640     int substickX;
641     int substickY;
642 
643     BOOL old;
644 
645     u32 i;
646 
647     u32 cpuCycles;
648     u32 userCycles;
649     u32 axCycles;
650     u32 voices;
651 
652     u32 maxCpuCycles =0;
653     u32 maxUserCycles=0;
654     u32 maxAxCycles  =0;
655     u32 maxVoices    =0;
656 
657 
658         substickX = (MenuPtr->handle)->pad.pads[0].substickX;
659         substickY = (MenuPtr->handle)->pad.pads[0].substickY;
660 
661         // Update panning position
662         if (positionIndex == 0)
663         {
664 
665             // if positionIndex is zero, then get panning information from
666             // the C-stick
667             panX = substickX + 63;
668             panY = (substickY - 63) * -1;
669 
670         }
671 
672         DEMOWinPrintfXY(window, 0, 1, "Pan       : %1.2f ", (f32)panX/127);
673         DEMOWinPrintfXY(window, 0, 2, "SPan      : %1.2f ", (f32)panY/127);
674 
675         old = OSDisableInterrupts();
676 
677         i = AXGetProfile();
678 
679         if (i)
680         {
681             // up to 4 audio frames can complete within a 60Hz video frame
682             // so spin thru the accumulated audio frame profiles and find the peak values
683             while (i)
684             {
685                 i--;
686 
687                 cpuCycles   = (u32)(ax_profile[i].axFrameEnd      - ax_profile[i].axFrameStart);
688                 userCycles  = (u32)(ax_profile[i].userCallbackEnd - ax_profile[i].userCallbackStart);
689                 axCycles    = cpuCycles - userCycles;
690                 voices      = ax_profile[i].axNumVoices;
691 
692                 // find peak values over the last i audio frames
693                 if (cpuCycles > maxCpuCycles)     maxCpuCycles    = cpuCycles;
694                 if (userCycles > maxUserCycles)   maxUserCycles   = userCycles;
695                 if (axCycles > maxAxCycles)       maxAxCycles     = axCycles;
696                 if (voices > maxVoices)           maxVoices       = voices;
697 
698             }
699             (void)OSRestoreInterrupts(old);
700 
701             DEMOWinPrintfXY(window, 0, 4, "Total CPU : %5.2f\n", (f32)OSTicksToNanoseconds(maxCpuCycles) / 50000);
702             DEMOWinPrintfXY(window, 0, 6, "User      : %5.2f\n", (f32)OSTicksToNanoseconds(maxUserCycles) / 50000);
703             DEMOWinPrintfXY(window, 0, 7, "AX        : %5.2f\n", (f32)OSTicksToNanoseconds(maxAxCycles) / 50000);
704             DEMOWinPrintfXY(window, 0, 9, "Voices    : %5d",    maxVoices);
705 
706         }
707 
708         (void)OSRestoreInterrupts(old);
709 
710 }
711 
712 /*---------------------------------------------------------------------------*
713  *---------------------------------------------------------------------------*/
LoadFileIntoRam(char * path)714 static void* LoadFileIntoRam(char *path)
715 {
716     DVDFileInfo handle;
717     u32         round_length;
718     s32         read_length;
719     void        *buffer;
720 
721     // Open File
722     if (!DVDOpen(path, &handle))
723     {
724         OSReport("WARNING! Failed to open %s\n", path);
725         return NULL;
726     }
727 
728     // Make sure file length is not 0
729     if (DVDGetLength(&handle) == 0)
730     {
731         OSReport("WARNING! File length is 0\n");
732         return NULL;
733     }
734 
735     round_length = OSRoundUp32B(DVDGetLength(&handle));
736     buffer       = MEMAllocFromExpHeapEx(hExpHeap, round_length,  32);
737 
738     // Make sure we got a buffer
739     if (buffer == NULL)
740     {
741         OSReport("WARNING! Unable to allocate buffer\n");
742         return NULL;
743     }
744 
745     // Read Files
746     read_length = DVDRead(&handle, buffer, (s32)(round_length), 0);
747 
748     // Make sure we read the file correctly
749     if (read_length <= 0)
750     {
751         OSReport("WARNING! File lenght is wrong\n");
752         return NULL;
753     }
754 
755     return buffer;
756 }
757 
758 /*---------------------------------------------------------------------------*
759  *---------------------------------------------------------------------------*/
PrivateAlloc(u32 size)760 static void* PrivateAlloc(u32 size)
761 {
762     return MEMAllocFromExpHeapEx(hExpHeap, size, 32);
763 }
764 
765 /*---------------------------------------------------------------------------*
766  *---------------------------------------------------------------------------*/
PrivateFree(void * addr)767 static void PrivateFree(void* addr)
768 {
769     MEMFreeToExpHeap(hExpHeap, addr);
770 }
771 
772 /*---------------------------------------------------------------------------*
773  * Name        : main()
774  * Description : Hold on to your seatbelts!
775  * Arguments   : None.
776  * Returns     : None.
777  *---------------------------------------------------------------------------*/
main(void)778 void main(void)
779 {
780     void       *arenaMem2Lo;
781     void       *arenaMem2Hi;
782     void       *axBuffer;
783     void       *mixBuffer;
784 
785     // initialize system
786     DEMOInit(NULL);
787     DEMOWinInit();
788 
789     SISetSamplingRate(5);
790 
791     arenaMem2Lo = OSGetMEM2ArenaLo();
792     arenaMem2Hi = OSGetMEM2ArenaHi();
793     hExpHeap    = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo);
794 
795     // initialize AI subsystem
796     AIInit(NULL);
797 
798     // initialize AX audio system and MIXer application
799     axBuffer  = MEMAllocFromExpHeapEx(hExpHeap, AXGetMemorySize(AX_MAX_VOICES), 32);
800     mixBuffer = MEMAllocFromExpHeap(hExpHeap, MIXGetMemorySize(AX_MAX_VOICES));
801 
802     AXInitSpecifyMem(AX_MAX_VOICES, axBuffer);
803     MIXInitSpecifyMem(mixBuffer);
804 
805     AXSetMode(AX_MODE_DPL2);
806     MIXSetSoundMode(MIX_SOUND_MODE_DPL2);
807 
808     // -----------------------------------------------------------
809     // Load SP data!
810     // -----------------------------------------------------------
811 
812     // Load sound table
813     sp_table = LoadFileIntoRam(SPT_FILE);
814 
815     // Load sound effects
816     sp_data  = LoadFileIntoRam(SPD_FILE);
817 
818     // -----------------------------------------------------------
819     // initialize sound table!
820     // -----------------------------------------------------------
821     SPInitSoundTable(sp_table, sp_data, NULL);
822 
823     // -----------------------------------------------------------
824     // Initialize demo voice abstraction layer
825     // -----------------------------------------------------------
826     AXRegisterCallback(ax_demo_callback);
827 
828     // -----------------------------------------------------------
829     // Initialize AUX-bus effects
830     // -----------------------------------------------------------
831     AXFXSetHooks((AXFXAlloc)PrivateAlloc, (AXFXFree)PrivateFree);
832     AXFX_PRESET_DELAY_EXP_TYPE1(&delay);
833     AXFXDelayExpInitDpl2(&delay);
834 
835     // -----------------------------------------------------------
836     // initialize profiling for AX
837     // -----------------------------------------------------------
838     AXInitProfile(ax_profile, NUM_AX_PROFILE_FRAMES);
839 
840     // -----------------------------------------------------------
841     // Invoke menu system!
842     // -----------------------------------------------------------
843     MenuPtr     = DEMOWinCreateMenuWindow(
844         &Menu,
845         20,
846         120
847         );
848 
849     DebugWin    = DEMOWinCreateWindow(
850         (u16)(MenuPtr->handle->x2+10),
851         20,
852         620,
853         440,
854         "Debug",
855         1024,
856         NULL
857         );
858 
859     PositionWin = DEMOWinCreateWindow(
860         (u16)(MenuPtr->handle->x1),
861         (u16)(MenuPtr->handle->y2+10),
862         (u16)(MenuPtr->handle->x2),
863         (u16)(MenuPtr->handle->y2+120),
864         "Position",
865         0,
866         position_win_update
867         );
868 
869     DEMOWinOpenWindow(DebugWin);
870     DEMOWinOpenWindow(PositionWin);
871 
872     DEMOWinLogPrintf(DebugWin, "-------------------------------------\n");
873     DEMOWinLogPrintf(DebugWin, "Delay (expanded version : Dpl2 ) Test\n");
874     DEMOWinLogPrintf(DebugWin, "-------------------------------------\n");
875 
876     DEMOWinLogPrintf(DebugWin, "\n");
877 
878     DEMOWinLogPrintf(DebugWin, "Mode is AX_MODE_DPL2.\n");
879 
880     while (1)
881     {
882 
883         DEMOWinMenu(MenuPtr);
884 
885     }
886 
887 } // end main()
888