1 /*---------------------------------------------------------------------------* 2 Project: Synth application for AX 3 File: syn.h 4 5 Copyright (C) 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 *---------------------------------------------------------------------------*/ 14 15 #ifndef __SYN_H__ 16 #define __SYN_H__ 17 18 #include <cafe/wt.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 //MOV alias 24 #define movMasterVolume drcMasterVolume 25 #define SYNMOVSetMasterVolume SYNDRCSetMasterVolume 26 #define SYNMOVGetMasterVolume SYNDRCGetMasterVolume 27 28 /*---------------------------------------------------------------------------* 29 synthesizer 30 *---------------------------------------------------------------------------*/ 31 32 #define SYN_INPUT_BUFFER_SIZE 256 33 34 typedef struct SYNSYNTH SYNSYNTH; 35 36 typedef void (*SYNCallback)(AXVPB *axvpb, SYNSYNTH *synth, u8 midiChannel); 37 38 struct SYNSYNTH 39 { 40 void *next; // synth list 41 42 WTINST *percussiveInst; // pointer to instrument[0] in wavetable 43 WTINST *melodicInst; // pointer to instrument[0] in wavetable 44 WTREGION *region; // pointer to region[0] in wavetable 45 WTART *art; // pointer to articulation[0] in wavetable 46 WTSAMPLE *sample; // pointer to sample[0] in wavetable 47 WTADPCM *adpcm; // pointer to adpcm[0] in wavetable 48 u8 *samples; // pointer to samples base as initialized 49 u32 priorityVoiceAlloc; // priority for allocating new note 50 u32 priorityNoteOn; // priority for notes that are on 51 u32 priorityNoteRelease; // priority for notes being released 52 53 WTINST *inst [16]; // pointer to instrument per channel 54 55 s32 masterVolume; // master TV volume for synth 56 s32 drcMasterVolume; // master DRC volume for synth 57 u32 mixerSelect; // play using DSP or PPC mixer 58 59 u8 controller [16][128]; // MIDI controller registers 60 61 u8 rpn [16]; // whether to enter rpn or nrpn data 62 s16 dataEntry [16]; // data entry value 63 64 s32 pwMaxCents [16]; // pitch wheel cents at + max 65 s32 pwCents [16]; // current pitch wheel cents 66 67 s32 volAttn [16]; // MIDI channel volume 68 s32 expAttn [16]; // expression volume 69 s32 auxAAttn [16]; // aux A (reverb) 70 s32 auxBAttn [16]; // aux B (chorus) 71 72 u8 input[SYN_INPUT_BUFFER_SIZE][3]; 73 u8 *inputPosition; 74 u32 inputCounter; 75 76 u32 notes; // notes running 77 78 void *keyGroup[16][16]; // storage for key group notes 79 void *voice[16][128]; // storage for voices index references 80 81 SYNCallback initCallback; 82 SYNCallback updateCallback; 83 84 }; 85 86 /*---------------------------------------------------------------------------* 87 a synthesizer voice 88 *---------------------------------------------------------------------------*/ 89 90 typedef struct SYNVOICE 91 { 92 // references to other objects 93 void *next; // used by synth 94 AXVPB *axvpb; // AX voice belonging to this voice 95 SYNSYNTH *synth; // this voice belongs to this synth 96 u8 midiChannel; // MIDI channel for this voice 97 u8 keyNum; // key number for this voice 98 u8 keyVel; // key velocity 99 u8 pan; // absolute panning for drum sounds 100 u8 keyGroup; // key group 1 - 15 101 102 // pointer to objects in wavetable 103 WTREGION *region; // instrument region 104 WTART *art; // articulation (VE, PE, LFO) 105 WTSAMPLE *sample; // sample data 106 WTADPCM *adpcm; // adpcm data 107 108 // on hold from hold pedal 109 u32 hold; // 1 if we are to hold after key off 110 111 // vars for voice processing 112 u32 type; // one shot or looped 113 f32 srcRatio; // base src ratio 114 s32 cents; // base relative pitch 115 s32 attn; // base attenuation (region + vel) 116 117 s32 lfoState; // LFO table index 118 s32 lfoAttn; // LFO attenuation 119 s32 lfoCents; // LFO pitch 120 s32 lfoFreq; // LFO table index / audio frame 121 s32 lfoDelay; // LFO delay in audio frames 122 s32 lfoAttn_; // LFO volume at 1.0 123 s32 lfoCents_; // LFO pitch at 1.0 124 s32 lfoModAttn; // LFO MOD wheel to attenuation 125 s32 lfoModCents; // LFO MOD wheel to cents 126 127 u32 veState; 128 s32 veAttn; // 0x00010000 = 0,1dB 129 s32 veAttack; // 0 - 99 table lookup for linear volume 130 s32 veAttackDelta; // add this to attack per frame 131 s32 veDecay; // 0x00010000 = 0,1dB per frame 132 s32 veSustain; // 0x00010000 = 0,1dB 133 s32 veRelease; // 0x00010000 = 0,1dB per frame 134 135 u32 peState; // state of envelope 136 s32 peCents; // current pitch 137 s32 peAttack; // pitch delta per frame 138 s32 peDecay; // pitch delta per frame 139 s32 peSustain; // pitch at sustain 140 s32 peRelease; // pitch delta per frame 141 s32 pePitch; // pitch cents at 100% 142 143 } SYNVOICE; 144 145 146 #define SYN_VOICE_TYPE_ONESHOT 0 147 #define SYN_VOICE_TYPE_LOOPED 1 148 149 #define SYN_VOICE_STATE_ATTACK 0 150 #define SYN_VOICE_STATE_DECAY 1 151 #define SYN_VOICE_STATE_SUSTAIN 2 152 #define SYN_VOICE_STATE_RELEASE 3 153 #define SYN_VOICE_STATE_DONE 4 154 155 /*---------------------------------------------------------------------------* 156 Exposed function prototypes 157 *---------------------------------------------------------------------------*/ 158 159 void SYNInit (void); 160 void SYNInitSpecifyMem (void* mem); 161 void SYNQuit (void); 162 163 #define SYNGetMemorySize(num) (sizeof(SYNVOICE) * num) 164 165 void SYNRunAudioFrame (void); 166 167 void SYNInitSynth ( 168 SYNSYNTH *synth, // user allocated synth 169 u8 *wavetable, // pointer to wave table 170 u8 *samples, // pointer to samples 171 u8 *zerobuffer, // pointer to zero buffer 172 u32 priorityVoiceAlloc, // priority for voice allocation 173 u32 priorityNoteOn, // priority for note on 174 u32 priorityNoteRelease // priority for note release 175 ); 176 177 void SYNQuitSynth (SYNSYNTH *synth); 178 void SYNMidiInput (SYNSYNTH *synth, u8 *input); 179 u8 SYNGetMidiController(SYNSYNTH *synth, u8 midiChannel, u8 function); 180 void SYNSetMasterVolume (SYNSYNTH *synth, s32 dB); 181 s32 SYNGetMasterVolume (SYNSYNTH *synth); 182 u32 SYNGetActiveNotes (SYNSYNTH *synth); 183 184 void SYNDRCSetMasterVolume (SYNSYNTH *synth, s32 dB); 185 s32 SYNDRCGetMasterVolume (SYNSYNTH *synth); 186 void SYNSetMixerSelect (SYNSYNTH *synth, u32 mixer); 187 u32 SYNGetMixerSelect (SYNSYNTH *synth); 188 189 SYNCallback SYNSetInitCallback (SYNSYNTH *synth, SYNCallback callback); 190 SYNCallback SYNSetUpdateCallback(SYNSYNTH *synth, SYNCallback callback); 191 192 193 #ifdef __cplusplus 194 } 195 #endif 196 197 #endif // __SYN_H__ 198