1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - include - snd - common 3 File: bank.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_BANK_H_ 19 #define NITRO_SND_COMMON_BANK_H_ 20 21 #include <nitro/snd/common/exchannel.h> // for SNDWaveParam 22 #include <nitro/snd/common/data.h> // for SNDBinaryFileHeader and SNDBinaryBlockHeader 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /****************************************************************************** 29 macro definition 30 ******************************************************************************/ 31 32 #define SND_INST_KEYSPLIT_MAX 8 33 34 #define SND_BANK_TO_WAVEARC_MAX 4 35 36 #define SND_BANK_DISABLE_RELEASE 255 37 38 /****************************************************************************** 39 structure declarations 40 ******************************************************************************/ 41 42 struct SNDWaveArc; 43 struct SNDExChannel; 44 45 /****************************************************************************** 46 enum definition 47 ******************************************************************************/ 48 49 typedef enum SNDInstType 50 { 51 SND_INST_INVALID = 0, 52 53 SND_INST_PCM = 0x01, 54 SND_INST_PSG, 55 SND_INST_NOISE, 56 SND_INST_DIRECTPCM, 57 SND_INST_NULL, 58 59 SND_INST_DRUM_SET = 0x10, 60 SND_INST_KEY_SPLIT 61 } 62 SNDInstType; 63 64 /****************************************************************************** 65 structure definition 66 ******************************************************************************/ 67 68 #ifdef _MSC_VER 69 #pragma warning( disable : 4200 ) // warning: zero-sized array in struct/union 70 #endif 71 72 typedef struct SNDWaveArcLink 73 { 74 struct SNDWaveArc *waveArc; 75 struct SNDWaveArcLink *next; 76 } 77 SNDWaveArcLink; 78 79 typedef struct SNDWaveArc 80 { 81 struct SNDBinaryFileHeader fileHeader; 82 struct SNDBinaryBlockHeader blockHeader; 83 84 struct SNDWaveArcLink *topLink; 85 u32 reserved[7]; 86 u32 waveCount; 87 u32 waveOffset[0]; 88 } 89 SNDWaveArc; 90 91 typedef struct SNDWaveData 92 { 93 struct SNDWaveParam param; 94 u8 samples[0]; 95 } 96 SNDWaveData; 97 98 typedef struct SNDBankData 99 { 100 struct SNDBinaryFileHeader fileHeader; 101 struct SNDBinaryBlockHeader blockHeader; 102 103 struct SNDWaveArcLink waveArcLink[SND_BANK_TO_WAVEARC_MAX]; 104 u32 instCount; 105 u32 instOffset[0]; 106 } 107 SNDBankData; 108 109 typedef struct SNDInstParam 110 { 111 u16 wave[2]; 112 u8 original_key; 113 u8 attack; 114 u8 decay; 115 u8 sustain; 116 u8 release; 117 u8 pan; 118 } 119 SNDInstParam; // Total 10Bytes 120 121 typedef struct SNDInstData 122 { 123 u8 type; // enum SNDInstType 124 u8 padding_; 125 126 struct SNDInstParam param; 127 } 128 SNDInstData; // Total 12Bytes 129 130 typedef struct SNDKeySplit 131 { 132 u8 key[SND_INST_KEYSPLIT_MAX]; 133 struct SNDInstData instOffset[0]; 134 } 135 SNDKeySplit; 136 137 typedef struct SNDDrumSet 138 { 139 u8 min; 140 u8 max; 141 struct SNDInstData instOffset[0]; 142 } 143 SNDDrumSet; 144 145 typedef struct SNDInstPos 146 { 147 u32 prgNo; 148 u32 index; 149 } 150 SNDInstPos; 151 152 #if defined(SDK_WIN32) || defined(SDK_FROM_TOOL) 153 154 struct SNDBankDataCallback; 155 typedef BOOL (__stdcall * SNDReadInstDataFunc) (const struct SNDBankDataCallback * bank, int prgNo, 156 int key, struct SNDInstData *inst); 157 158 typedef struct SNDBankDataCallback 159 { 160 struct SNDBinaryFileHeader fileHeader; 161 struct SNDBinaryBlockHeader blockHeader; 162 163 void *arg; 164 SNDReadInstDataFunc readInstDataFunc; 165 } 166 SNDBankDataCallback; 167 168 #endif 169 170 #ifdef _MSC_VER 171 #pragma warning( default : 4200 ) // warning: zero-sized array in struct/union 172 #endif 173 174 /****************************************************************************** 175 public functions 176 ******************************************************************************/ 177 178 void SND_AssignWaveArc(struct SNDBankData *bank, int index, struct SNDWaveArc *waveArc); 179 void SND_DestroyBank(struct SNDBankData *bank); 180 void SND_DestroyWaveArc(struct SNDWaveArc *waveArc); 181 182 BOOL SND_ReadInstData(const struct SNDBankData *bank, int prgNo, int key, 183 struct SNDInstData *inst); 184 BOOL SND_WriteInstData(struct SNDBankData *bank, int prgNo, int key, 185 const struct SNDInstData *inst); 186 187 struct SNDInstPos SND_GetFirstInstDataPos(const struct SNDBankData *bank); 188 BOOL SND_GetNextInstData(const struct SNDBankData *bank, struct SNDInstData *inst, 189 struct SNDInstPos *pos); 190 191 u32 SND_GetWaveDataCount(const struct SNDWaveArc *waveArc); 192 void SND_SetWaveDataAddress(struct SNDWaveArc *waveArc, int index, const SNDWaveData *address); 193 const SNDWaveData *SND_GetWaveDataAddress(const struct SNDWaveArc *waveArc, int index); 194 195 #ifdef SDK_ARM7 196 197 BOOL SND_NoteOn(struct SNDExChannel *ch_p, 198 int key, 199 int velocity, 200 s32 length, const struct SNDBankData *bank, const struct SNDInstData *inst); 201 202 #endif /* SDK_ARM7 */ 203 204 #ifdef __cplusplus 205 } /* extern "C" */ 206 #endif 207 208 #endif /* NITRO_SND_COMMON_BANK_H_ */ 209