1 /*---------------------------------------------------------------------------* 2 Project: Synth application for AX 3 File: syn.h 4 5 Copyright (C)1998-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: syn.h,v $ 14 Revision 1.10 2006/11/21 04:57:08 aka 15 Removed zeroBaseXXX from SYNSYNTH structure. 16 17 Revision 1.9 2006/10/23 01:39:50 aka 18 Rolled-back SYNInit(). 19 Added SYNInitSpecifyMem(). 20 21 Revision 1.8 2006/10/19 02:51:31 aka 22 Added a definition of SYNVOICE. 23 Revised SYNGetMemorySize(). 24 25 Revision 1.7 2006/10/10 04:53:09 aka 26 Removed SYNSetMemory(). 27 Revised SYNInit(). 28 29 Revision 1.6 2006/10/10 02:40:06 aka 30 Added SYNGetMemorySize(). 31 Added SYNSetMemory(). 32 33 Revision 1.5 2006/07/25 08:07:55 aka 34 Modified to support controller speakers. 35 36 Revision 1.4 2006/01/31 06:02:06 aka 37 Changed arguments of SYNInitSynth(). 38 39 Revision 1.3 2006/01/30 11:50:10 aka 40 Changed copyright. 41 42 Revision 1.2 2006/01/30 11:31:35 aka 43 Renamed from ARAM to MRAM. 44 45 Revision 1.1.1.1 2005/05/12 02:41:07 yasuh-to 46 Imported from dolphin tree. 47 48 2 8/16/01 12:27p Billyjack 49 added zeroBuffer offset to API 50 51 1 5/09/01 1:28p Billyjack 52 created 53 54 $NoKeywords: $ 55 *---------------------------------------------------------------------------*/ 56 57 #ifndef __SYN_H__ 58 #define __SYN_H__ 59 60 #include <revolution/wt.h> 61 62 #ifdef __cplusplus 63 extern "C" { 64 #endif 65 66 /*---------------------------------------------------------------------------* 67 synthesizer 68 *---------------------------------------------------------------------------*/ 69 70 #define SYN_INPUT_BUFFER_SIZE 256 71 72 typedef struct SYNSYNTH SYNSYNTH; 73 74 typedef void (*SYNCallback)(AXVPB *axvpb, SYNSYNTH *synth, u8 midiChannel); 75 76 struct SYNSYNTH 77 { 78 void *next; // synth list 79 80 WTINST *percussiveInst; // pointer to instrument[0] in wavetable 81 WTINST *melodicInst; // pointer to instrument[0] in wavetable 82 WTREGION *region; // pointer to region[0] in wavetable 83 WTART *art; // pointer to articulation[0] in wavetable 84 WTSAMPLE *sample; // pointer to sample[0] in wavetable 85 WTADPCM *adpcm; // pointer to adpcm[0] in wavetable 86 u32 samplesBaseWord; // base address (16bit) of samples in RAM 87 u32 samplesBaseByte; // base address (8bit)of samples in RAM 88 u32 samplesBaseNibble; // base address (nibble) of samples in RAM 89 u32 priorityVoiceAlloc; // priority for allocating new note 90 u32 priorityNoteOn; // priority for notes that are on 91 u32 priorityNoteRelease; // peiority for nots being released 92 93 WTINST *inst [16]; // pointer to instrument per channel 94 95 s32 masterVolume; // master volume for synth 96 97 u8 controller [16][128]; // MIDI controller registers 98 99 u8 rpn [16]; // weather to enter rpn or nrpn data 100 s16 dataEntry [16]; // data entry value 101 102 s32 pwMaxCents [16]; // pitch wheel cents at + max 103 s32 pwCents [16]; // current pitch wheel cents 104 105 s32 volAttn [16]; // MIDI channel volume 106 s32 expAttn [16]; // expression volume 107 s32 auxAAttn [16]; // aux A (reverb) 108 s32 auxBAttn [16]; // aux B (chorus) 109 110 u8 input[SYN_INPUT_BUFFER_SIZE][3]; 111 u8 *inputPosition; 112 u32 inputCounter; 113 114 u32 notes; // notes running 115 116 void *keyGroup[16][16]; // storage for key group notes 117 void *voice[16][128]; // storage for voices index references 118 119 SYNCallback initCallback; 120 SYNCallback updateCallback; 121 122 }; 123 124 /*---------------------------------------------------------------------------* 125 a synthesizer voice 126 *---------------------------------------------------------------------------*/ 127 128 typedef struct SYNVOICE 129 { 130 // references to other objects 131 void *next; // used by synth 132 AXVPB *axvpb; // AX voice belonging to this voice 133 SYNSYNTH *synth; // this voice belongs to this synth 134 u8 midiChannel; // MIDI channel for this voice 135 u8 keyNum; // key number for this voice 136 u8 keyVel; // key velocity 137 u8 pan; // absolute panning for drum sounds 138 u8 keyGroup; // key group 1 - 15 139 140 // pointer to objects in wavetable 141 WTREGION *region; // instrument region 142 WTART *art; // articulation (VE, PE, LFO) 143 WTSAMPLE *sample; // sample data 144 WTADPCM *adpcm; // adpcm data 145 146 // on hold from hold pedal 147 u32 hold; // 1 if we are to hold after key off 148 149 // vars for voice processing 150 u32 type; // one shot or looped 151 f32 srcRatio; // base src ratio 152 s32 cents; // base relitive pitch 153 s32 attn; // base attenuation (region + vel) 154 155 s32 lfoState; // LFO table index 156 s32 lfoAttn; // LFO attenaution 157 s32 lfoCents; // LFO pitch 158 s32 lfoFreq; // LFO table index / audio frame 159 s32 lfoDelay; // LFO delay in audio frames 160 s32 lfoAttn_; // LFO volume at 1.0 161 s32 lfoCents_; // LFO pitch at 1.0 162 s32 lfoModAttn; // LFO MOD wheel to attenuation 163 s32 lfoModCents; // LFO MOD wheel to cents 164 165 u32 veState; 166 s32 veAttn; // 0x00010000 = 0,1dB 167 s32 veAttack; // 0 - 99 table lookup for linear volume 168 s32 veAttackDelta; // add this to attack per frame 169 s32 veDecay; // 0x00010000 = 0,1dB per frame 170 s32 veSustain; // 0x00010000 = 0,1dB 171 s32 veRelease; // 0x00010000 = 0,1dB per frame 172 173 u32 peState; // state of envelope 174 s32 peCents; // current pitch 175 s32 peAttack; // pitch delta per frame 176 s32 peDecay; // pitch delta per frame 177 s32 peSustain; // pitch at sustain 178 s32 peRelease; // pitch delta per frame 179 s32 pePitch; // pitch cents at 100% 180 181 } SYNVOICE; 182 183 184 #define SYN_VOICE_TYPE_ONESHOT 0 185 #define SYN_VOICE_TYPE_LOOPED 1 186 187 #define SYN_VOICE_STATE_ATTACK 0 188 #define SYN_VOICE_STATE_DECAY 1 189 #define SYN_VOICE_STATE_SUSTAIN 2 190 #define SYN_VOICE_STATE_RELEASE 3 191 #define SYN_VOICE_STATE_DONE 4 192 193 /*---------------------------------------------------------------------------* 194 Exposed function prototypes 195 *---------------------------------------------------------------------------*/ 196 197 void SYNInit (void); 198 void SYNInitSpecifyMem (void* mem); 199 void SYNQuit (void); 200 201 #define SYNGetMemorySize(num) (sizeof(SYNVOICE) * num) 202 203 void SYNRunAudioFrame (void); 204 205 void SYNInitSynth ( 206 SYNSYNTH *synth, // user allocated synth 207 u8 *wavetable, // pointer to wave table 208 u8 *samples, // pointer to samples 209 u8 *zerobuffer, // pointer to zero buffer 210 u32 priorityVoiceAlloc, // priority for voice allocation 211 u32 priorityNoteOn, // priority for note on 212 u32 priorityNoteRelease // priority for note release 213 ); 214 215 void SYNQuitSynth (SYNSYNTH *synth); 216 void SYNMidiInput (SYNSYNTH *synth, u8 *input); 217 u8 SYNGetMidiController(SYNSYNTH *synth, u8 midiChannel, u8 function); 218 void SYNSetMasterVolume (SYNSYNTH *synth, s32 dB); 219 s32 SYNGetMasterVolume (SYNSYNTH *synth); 220 u32 SYNGetActiveNotes (SYNSYNTH *synth); 221 222 SYNCallback SYNSetInitCallback (SYNSYNTH *synth, SYNCallback callback); 223 SYNCallback SYNSetUpdateCallback(SYNSYNTH *synth, SYNCallback callback); 224 225 226 #ifdef __cplusplus 227 } 228 #endif 229 230 #endif // __SYN_H__ 231