1 /*---------------------------------------------------------------------------*
2 Project: THP Simple Player
3 File: axseq.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: axseq.c,v $
14 Revision 1.4 2006/03/06 09:59:09 kawaset
15 Eliminated warnings.
16
17 Revision 1.3 02/21/2006 01:04:26 mitu
18 modified am.h path.
19
20 Revision 1.2 02/20/2006 04:13:12 mitu
21 changed include path from dolphin/ to revolution/.
22
23 Revision 1.1 02/03/2006 10:01:13 aka
24 Imported from Dolphin tree.
25
26
27 1 02/02/28 6:39p Akagi
28 Initial revision made by Suzuki-san (IRD).
29
30 $NoKeywords: $
31
32 *---------------------------------------------------------------------------*/
33
34 #include <revolution.h>
35 #include <revolution/mix.h>
36 #include <revolution/seq.h>
37 #include <revolution/syn.h>
38 #include <revolution/axfx.h>
39 #ifndef HOLLYWOOD_REV
40 #include <dolphin/am.h>
41 #else
42 #include <revolution/mem.h>
43 #include <string.h>
44 #endif
45
46 #include "axseq.h"
47
48 static void CallbackAudioFrame(void);
49
50 #ifndef HOLLYWOOD_REV
51 static u32 AramMemArray[MAX_ARAM_BLOCKS];
52 #endif
53
54 static SEQSEQUENCE Sequence;
55 static u8 *Wavetable;
56 static u8 *Pcm;
57 static u8 *ZeroBase;
58 static u8 *MidiFile;
59
60 #ifdef HOLLYWOOD_REV
61 #define ZEROBUFFER_BYTES 256
62
63 extern MEMHeapHandle __ExpHeap;
64 #endif
65
CallbackAudioFrame(void)66 static void CallbackAudioFrame(void)
67 {
68 int old = OSEnableInterrupts();
69
70 // run the sequencer
71 SEQRunAudioFrame();
72
73 // run the synth
74 SYNRunAudioFrame();
75
76 // tell the mixer to update settings
77 MIXUpdateSettings();
78
79 OSRestoreInterrupts(old);
80 }
81
82 #ifdef HOLLYWOOD_REV
83 /*---------------------------------------------------------------------------*
84 *---------------------------------------------------------------------------*/
LoadFileIntoRam(char * path)85 static void* LoadFileIntoRam(char *path)
86 {
87 DVDFileInfo handle;
88 u32 round_length;
89 s32 read_length;
90 void *buffer;
91
92 // Open File
93 if (!DVDOpen(path, &handle))
94 {
95 OSReport("WARNING! Failed to open %s\n", path);
96 return NULL;
97 }
98
99 // Make sure file length is not 0
100 if (DVDGetLength(&handle) == 0)
101 {
102 OSReport("WARNING! File length is 0\n");
103 return NULL;
104 }
105
106 round_length = OSRoundUp32B(DVDGetLength(&handle));
107 buffer = MEMAllocFromExpHeapEx(__ExpHeap, round_length, 32);
108
109 // Make sure we got a buffer
110 if (buffer == NULL)
111 {
112 OSReport("WARNING! Unable to allocate buffer\n");
113 return NULL;
114 }
115
116 // Read Files
117 read_length = DVDRead(&handle, buffer, (s32)(round_length), 0);
118
119 // Make sure we read the file correctly
120 if (read_length <= 0)
121 {
122 OSReport("WARNING! File lenght is wrong\n");
123 return NULL;
124 }
125
126 return buffer;
127 }
128 #endif
129
AXSeqSetup(void)130 void AXSeqSetup(void)
131 {
132 #ifndef HOLLYWOOD_REV
133 u32 aramSize, aramBase;
134 #endif
135
136 #ifndef HOLLYWOOD_REV
137 ARInit(AramMemArray, MAX_ARAM_BLOCKS);
138 ARQInit();
139 #endif
140
141 AXInit(); // initialize AX
142 MIXInit(); // initialize mixer
143 SYNInit(); // initialize synthesizer
144 SEQInit(); // initialize sequencer
145 AXRegisterCallback(&CallbackAudioFrame);
146
147 #ifndef HOLLYWOOD_REV
148 aramSize = ARGetSize() - ARGetBaseAddress();
149 aramBase = ARAlloc(aramSize);
150 AMInit(aramBase, aramSize);
151
152 Wavetable = AMLoadFile(GM_WT, NULL);
153 Pcm = (u8*)AMPush(GM_PCM);
154
155 ZeroBase = (u8*)AMGetZeroBuffer();
156
157 MidiFile = AMLoadFile(MIDI_FILE, NULL);
158 #else
159 Wavetable = LoadFileIntoRam(GM_WT);
160 Pcm = LoadFileIntoRam(GM_PCM);
161 MidiFile = LoadFileIntoRam(MIDI_FILE);
162
163 ZeroBase = MEMAllocFromExpHeapEx(__ExpHeap, ZEROBUFFER_BYTES, 8);
164 memset(ZeroBase, 0, ZEROBUFFER_BYTES);
165 DCFlushRange(ZeroBase, ZEROBUFFER_BYTES);
166 #endif
167
168 SEQAddSequence( &Sequence,
169 MidiFile,
170 Wavetable,
171 Pcm,
172 ZeroBase,
173 16,
174 15,
175 1
176 );
177 }
178
SeqPlay(void)179 void SeqPlay(void)
180 {
181 SEQSetState(&Sequence, SEQ_STATE_RUNLOOPED);
182
183 return;
184 }
185
SeqStop(void)186 void SeqStop(void)
187 {
188 SEQSetState(&Sequence, SEQ_STATE_STOP);
189
190 return;
191 }
192
GetSeqState(void)193 BOOL GetSeqState(void)
194 {
195 if (SEQGetState(&Sequence) == SEQ_STATE_RUNLOOPED)
196 {
197 return TRUE;
198 }
199 else
200 {
201 return FALSE;
202 }
203 }
204