1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - include - snd - common
3   File:     seq.h
4 
5   Copyright 2004-2008 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   $Date:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NITRO_SND_COMMON_SEQ_H_
19 #define NITRO_SND_COMMON_SEQ_H_
20 
21 #include <nitro/types.h>
22 
23 #include <nitro/snd/common/exchannel.h> // for SNDLfoParam
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /******************************************************************************
30 	Macro Definitions
31  ******************************************************************************/
32 
33 #define SND_PLAYER_NUM 16
34 #define SND_PLAYER_MIN  0
35 #define SND_PLAYER_MAX 15
36 
37 #define SND_TRACK_NUM 32
38 #define SND_TRACK_MIN  0
39 #define SND_TRACK_MAX 31
40 
41 #define SND_TRACK_NUM_PER_PLAYER 16
42 
43 #define SND_INVALID_TRACK_INDEX 0xff
44 
45 #define SND_BASE_TEMPO    240
46 #define SND_DEFAULT_TEMPO 120
47 
48 #define SND_TRACK_CALL_STACK_DEPTH 3
49 
50 // Caution: This affects the size of SNDSharedWork
51 #define SND_PLAYER_VARIABLE_NUM 16
52 #define SND_GLOBAL_VARIABLE_NUM 16
53 
54 /******************************************************************************
55 	Enum Definitions
56  ******************************************************************************/
57 
58 typedef enum
59 {
60     SND_SEQ_MUTE_OFF,
61     SND_SEQ_MUTE_NO_STOP,
62     SND_SEQ_MUTE_RELEASE,
63     SND_SEQ_MUTE_STOP
64 }
65 SNDSeqMute;
66 
67 /******************************************************************************
68 	Structure Declaration
69  ******************************************************************************/
70 
71 struct SNDBankData;
72 
73 /******************************************************************************
74 	Structure Definitions
75  ******************************************************************************/
76 
77 typedef struct SNDPlayer
78 {
79     u8      active_flag:1;
80     u8      prepared_flag:1;
81     u8      pause_flag:1;
82     u8      pad_:5;
83 
84     u8      myNo;
85     u8      pad2_;
86     u8      pad3_;
87 
88     u8      prio;
89     u8      volume;
90     s16     extFader;
91 
92     u8      tracks[SND_TRACK_NUM_PER_PLAYER];
93 
94     u16     tempo;
95     u16     tempo_ratio;
96     u16     tempo_counter;
97     u16     pad__;
98 
99     struct SNDBankData *bank;
100 }
101 SNDPlayer;
102 
103 typedef struct SNDTrack
104 {
105     u8      active_flag:1;
106     u8      note_wait:1;
107     u8      mute_flag:1;
108     u8      tie_flag:1;
109     u8      note_finish_wait:1;
110     u8      porta_flag:1;
111     u8      cmp_flag:1;
112     u8      channel_mask_flag:1;
113 
114     u8      pan_range;
115 
116     u16     prgNo;
117 
118     u8      volume;
119     u8      volume2;
120     s8      pitch_bend;
121     u8      bend_range;
122 
123     s8      pan;
124     s8      ext_pan;
125     s16     extFader;
126     s16     ext_pitch;
127 
128     u8      attack;
129     u8      decay;
130     u8      sustain;
131     u8      release;
132 
133     u8      prio;
134     s8      transpose;
135     u8      porta_key;
136     u8      porta_time;
137     s16     sweep_pitch;
138 
139     struct SNDLfoParam mod;
140     u16     channel_mask;
141 
142     s32     wait;
143 
144     const u8 *base;                    // Note: MainMemory pointer
145     const u8 *cur;                     // Note: MainMemory pointer
146 
147     const u8 *call_stack[SND_TRACK_CALL_STACK_DEPTH];
148     u8      loop_count[SND_TRACK_CALL_STACK_DEPTH];
149     u8      call_stack_depth;
150 
151     struct SNDExChannel *channel_list;
152 }
153 SNDTrack;
154 
155 /******************************************************************************
156 	Public Function Declarations
157  ******************************************************************************/
158 
159 #ifdef SDK_ARM7
160 
161 void    SND_SeqInit(void);
162 void    SND_SeqMain(BOOL doPeriodicProc);
163 
164 void    SND_StartSeq(int playerNo, const void *seqBase, u32 seqOffset, struct SNDBankData *bank_p);
165 void    SND_StopSeq(int playerNo);
166 void    SND_PrepareSeq(int playerNo, const void *seqBase, u32 seqOffset,
167                        struct SNDBankData *bank_p);
168 void    SND_StartPreparedSeq(int playerNo);
169 void    SND_PauseSeq(int playerNo, BOOL flag);
170 void    SND_SkipSeq(int playerNo, u32 tick);
171 
172 void    SND_SetTrackMute(int playerNo, u32 trackBitMask, SNDSeqMute mute);
173 void    SND_SetTrackAllocatableChannel(int playerNo, u32 trackBitMask, u32 chBitMask);
174 
175 void    SND_InvalidateSeq(const void *start, const void *end);
176 void    SND_InvalidateBank(const void *start, const void *end);
177 
178 void    SND_MmlPrintEnable(BOOL enble);
179 
180 #endif /* SDK_ARM7 */
181 
182 /******************************************************************************
183 	Private Function Declarations
184  ******************************************************************************/
185 
186 #ifdef SDK_ARM7
187 
188 void    SNDi_SetPlayerParam(int playerNo, u32 offset, u32 data, int size);
189 void    SNDi_SetTrackParam(int playerNo, u32 trackBitMask, u32 offset, u32 data, int size);
190 
191 #endif /* SDK_ARM7 */
192 
193 
194 #ifdef __cplusplus
195 } /* extern "C" */
196 #endif
197 
198 #endif /* NITRO_SND_COMMON_SEQ_H_ */
199