resonance 1.0.1
Loading...
Searching...
No Matches
hsyn.h
Go to the documentation of this file.
1#ifndef EZMIDI_HSYN_H
2#define EZMIDI_HSYN_H
3
4#include "ezmidi/ezmidi.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
15
17#define HSYN_CHANNELS 16
18
20#define HSYN_BANKS 16
21
23#define HSYN_NOTES 50
24
26#define HSYN_CORES 2
27
29#define HSYN_VOICES_PER_CORE 24
30
32#define HSYN_SLAVE_VOICE 255
33
35enum {
36 HSYN_NOTE_ON = 0x01,
40};
41
43enum {
46};
47
49enum {
55};
56
58typedef struct {
59 unsigned char iProg;
60 unsigned char iVol;
61 unsigned char iPan;
62 unsigned char iExp;
63 unsigned short iBank;
64 unsigned short iMod;
65 unsigned short iPitch;
66 unsigned char iBankHi;
67 unsigned char iFx;
68 unsigned char iPri;
69 unsigned char iPadc;
70 unsigned short iPads;
72
74typedef struct {
75 unsigned char chan;
76 unsigned char note;
77 unsigned char slot;
78 unsigned char slave;
79 unsigned char flag;
80 unsigned char fx;
81 unsigned short i_vol;
82 unsigned short i_pitch;
83 unsigned char i_pan;
84 unsigned char i_pad;
85 unsigned short c_pitch;
86 unsigned short c_vol[2];
87 unsigned short t_vol[2];
88 unsigned short chr_idx;
89 unsigned short chr_rng;
90 unsigned short stt_targ[2];
91 unsigned char stt_frame[2];
92 unsigned char pri;
93 unsigned char bank;
94 unsigned char pada[6];
95} sSynNote;
96
98typedef struct {
99 unsigned short run_chr_rate[2];
100 unsigned char remix_mode;
101 unsigned char mono_mode;
102} sSynthRun;
103
105typedef struct {
108 int count;
109} TimerCtx;
110
112typedef struct {
113 unsigned char reserved[36];
118} sHdHeader;
119
121typedef struct {
122 unsigned char reserved[12];
124 int offsets[];
125} sHdChunk;
126
128typedef struct {
129 unsigned short sampleSetIndex;
130 unsigned char rangeLow;
131 unsigned char reserved3;
132 unsigned char rangeHigh;
133 unsigned char reserved5[11];
134 unsigned char volume;
135 unsigned char pan;
136 signed char transpose;
137 signed char detune;
138} sHdSplit;
139
141typedef struct {
142 unsigned char reserved0[4];
143 unsigned char splitCount;
144 unsigned char reserved5;
145 unsigned char volume;
146 unsigned char pan;
147 signed char transpose;
148 signed char detune;
149 unsigned char reserved[26];
151} sHdProgram;
152
154typedef struct {
155 unsigned char reserved[4];
156 unsigned short sampleIndex[];
158
160typedef struct {
161 short vagIndex;
162 unsigned char reserved2[9];
163 unsigned char baseNote;
164 unsigned char reserved12;
165 unsigned char pan;
166 unsigned char reserved14[2];
167 unsigned char volume;
168 unsigned char reserved17;
169 unsigned short adsr1;
170 unsigned short adsr2;
171 unsigned char reserved22[19];
172 unsigned char spuAttr;
173} sHdSample;
174
176typedef struct {
177 unsigned int offset;
178 unsigned short sampleRate;
179 unsigned char attribute;
180} sHdVagInfo;
181
183#define HD_VAG_LOOPED 1
184
186extern unsigned char *gpHd;
187
189extern unsigned char *gpBd;
190
192extern unsigned char *gaHds[HSYN_BANKS];
193
195extern unsigned char *gaBds[HSYN_BANKS];
196
199
201extern int voice_alloc[HSYN_CORES];
202
205
207extern int gEndX[HSYN_CORES];
208
210extern int gVMixL[HSYN_CORES];
211
213extern int gVMixR[HSYN_CORES];
214
216extern int gVMixEL[HSYN_CORES];
217
219extern int gVMixER[HSYN_CORES];
220
222extern int gReg_VMixL[HSYN_CORES];
223
225extern int gReg_VMixR[HSYN_CORES];
226
228extern int gReg_VMixEL[HSYN_CORES];
229
231extern int gReg_VMixER[HSYN_CORES];
232
234extern int rate_L;
235
237extern int rate_R;
238
246void _build_chorus(int iDepth);
247
257int HandleTransIntr(int ch, void *common);
258
269int MemCpy_IOPtoSPU(void *pIOP, void *pSPU, int iBlockSize);
270
281int StartAutoDMA(void *pIOP, void *pSPU, int iDirection);
282
293int StopAutoDMA(void *pIOP, void *pSPU, int iDirection);
294
301void _init_channels(void);
302
309void _init_banks(void);
310
319void hs_prog_change(int iChan, int iProg);
320
329int get_free_slot(int which_core);
330
342int _note_2_pitch(int base_note, int new_note, int detune, int samp_rate);
343
353int _apply_channel_to_note(sSynNote *pNote, int do_set);
354
369int _fire_off_sample(int iSamp,
370 int iNote,
371 int iChan,
372 int iVol,
373 sHdProgram *pProgOffs,
374 sHdSplit *pSplitOffs,
375 int xflags);
376
387int hs_note_on(int iChan, int iNote, int iVol);
388
398int hs_kill_idx(sSynNote *pNote, int iAlreadyOff);
399
408int hs_idx_off(int noteidx);
409
419int hs_note_off(int iChan, int iNote);
420
430
442unsigned short _apply_chorus(unsigned short c_pitch,
443 unsigned short rate,
444 unsigned short depth,
445 unsigned short *pos);
446
456
465int hs_reapply_channel(int iChan);
466
475int ShowSynthState(int iFlags);
476
484
491void _do_reg_out(void);
492
501void HardSynthAllNotesOff(int iChan, int do_now);
502
511unsigned char *HandleMidiMessage(unsigned char *pMidiMsg);
512
523int HardSynthLoadBD(int ipBd, int ipSpu, int iSize);
524
536int HardSynthAttachHDtoBD(int port, int ipHd, int ipSpu, int bank);
537
547
555void HardSynthInvalidateHd(unsigned char *pHd);
556
565
573
582
591
602int HardSynthParseNew(unsigned char *pMidiBlock, int iBlockSize, int buf);
603
612
621
630int HardSynthSetRemix(int parm);
631
640int HardSynthSetMono(int parm);
641
650
659
668
677
685void HardSynthInfo(int what);
686
687#ifdef __cplusplus
688}
689#endif
690
691#endif
int HardSynthShutdown(void)
Stop and release the tick timer.
int gVMixR[HSYN_CORES]
Dry right mix switches read from the SPU2 each tick, one word per core.
int HardSynthUpdate(void)
Apply one tick of updates to every sounding note.
void HardSynthInvalidateHd(unsigned char *pHd)
Detach the bank slot that uses a header.
int get_free_slot(int which_core)
Find a free voice, starting after the one handed out last on each core.
void hs_prog_change(int iChan, int iProg)
Select a channel's program.
unsigned char * gaBds[HSYN_BANKS]
SPU2 addresses of the bank bodies by bank slot.
sSynChannel gChan[HSYN_CHANNELS]
Channel state.
int rate_R
Right chorus rate.
int HardSynthClearHDBD(void)
Clear the flag an attached bank sets.
int HardSynthInvalidateBank(int bank)
Detach a bank slot and silence its notes.
int HardSynthKillOld(void)
Release every note whose voice has fallen silent.
void MidiBufferSetup(void)
Empty the MIDI stream buffers.
int _fire_off_sample(int iSamp, int iNote, int iChan, int iVol, sHdProgram *pProgOffs, sHdSplit *pSplitOffs, int xflags)
Key on one sample of a program on a new voice.
sSynNote gCurrentNotes[HSYN_NOTES]
Sounding notes.
@ HSYN_NOTE_RELEASED
Definition hsyn.h:39
@ HSYN_NOTE_ON
Definition hsyn.h:36
@ HSYN_NOTE_NEW
Definition hsyn.h:37
@ HSYN_NOTE_LOOPED
Definition hsyn.h:38
int gVMixL[HSYN_CORES]
Dry left mix switches read from the SPU2 each tick, one word per core.
unsigned char * gpBd
SPU2 address of the bank body of the note being started.
int gReg_VMixL[HSYN_CORES]
Dry left mix switches to write at the end of the tick, one word per core.
int gVMixER[HSYN_CORES]
Effect right mix switches read from the SPU2 each tick, one word per core.
int HardSynthInit(void)
Initialise the synthesiser, start its tick thread, and start the tick timer.
int gVMixEL[HSYN_CORES]
Effect left mix switches read from the SPU2 each tick, one word per core.
int gReg_VMixEL[HSYN_CORES]
Effect left mix switches to write at the end of the tick, one word per core.
int hs_reapply_channel(int iChan)
Recompute and write every note of a channel.
int voice_alloc[HSYN_CORES]
Voices in use, one bit per voice and one word per core.
int HardSynthParseNew(unsigned char *pMidiBlock, int iBlockSize, int buf)
Act on a block of MIDI messages.
int hs_check_playing(sSynNote *pNote)
Release a note whose voice has fallen silent.
unsigned char * HandleMidiMessage(unsigned char *pMidiMsg)
Act on one MIDI channel message.
int gReg_VMixR[HSYN_CORES]
Dry right mix switches to write at the end of the tick, one word per core.
void HardSynthConfig(sSynthConfig *pConfig)
Replace the settings and recompute the chorus rates.
void _do_reg_out(void)
Write the key-on, key-off, and changed voice mix switches of both cores.
void HardSynthInfo(int what)
Handle a diagnostic request.
int HandleTransIntr(int ch, void *common)
Count one completed SPU2 transfer.
int HardSynthResume(void)
Restore the pitch of every note HardSynthPause() stopped.
void _init_banks(void)
Detach every bank slot.
int hs_kill_idx(sSynNote *pNote, int iAlreadyOff)
Silence a note at once and release its voice.
int gEndX[HSYN_CORES]
Voices whose sample has ended, one word per core, read each tick.
#define HSYN_NOTES
Notes the synthesiser can have sounding at once.
Definition hsyn.h:23
int ShowSynthState(int iFlags)
Print the synthesiser state.
int HardSynthAttachHDtoBD(int port, int ipHd, int ipSpu, int bank)
Attach a bank header and its body to a bank slot.
int HardSynthLoadBD(int ipBd, int ipSpu, int iSize)
Copy a bank body to SPU2 memory.
int _note_2_pitch(int base_note, int new_note, int detune, int samp_rate)
Convert a note to a pitch register value for a sample.
int hs_note_on(int iChan, int iNote, int iVol)
Start a note on a channel.
@ HSYN_FX_KEEP_PAN
Definition hsyn.h:44
@ HSYN_FX_CHORUS
Definition hsyn.h:45
int HardSynthPause(void)
Stop the pitch of every note on the channels pausing affects.
int MemCpy_IOPtoSPU(void *pIOP, void *pSPU, int iBlockSize)
Copy IOP memory to SPU2 memory and wait for the transfer to end.
int gReg_VMixER[HSYN_CORES]
Effect right mix switches to write at the end of the tick, one word per core.
int _apply_channel_to_note(sSynNote *pNote, int do_set)
Recompute a note's volume and pitch from its channel.
@ HSYN_CHAN_FX_CHORUS
Definition hsyn.h:52
@ HSYN_CHAN_FX_CORE0_EFFECT
Definition hsyn.h:54
@ HSYN_CHAN_FX_CORE1_EFFECT
Definition hsyn.h:53
@ HSYN_CHAN_FX_SMOOTH_VOL
Definition hsyn.h:51
@ HSYN_CHAN_FX_KEEP_PAN
Definition hsyn.h:50
void ResetSynthState(void)
Reset every program, voice, channel, and bank slot.
int hs_idx_off(int noteidx)
Key off a note by index.
int rate_L
Left chorus rate.
int hs_note_off(int iChan, int iNote)
Key off the note playing on a channel, with its chorus voice.
int HardSynthReset(void)
Reset the synthesiser state.
void _build_chorus(int iDepth)
Fill the quarter-sine chorus curve.
unsigned char * gaHds[HSYN_BANKS]
Bank headers by bank slot.
unsigned short _apply_chorus(unsigned short c_pitch, unsigned short rate, unsigned short depth, unsigned short *pos)
Advance a chorus position and apply it to a pitch.
int StopAutoDMA(void *pIOP, void *pSPU, int iDirection)
Stop an automatic DMA stream.
#define HSYN_CORES
SPU2 cores, each with its own voices.
Definition hsyn.h:26
#define HSYN_CHANNELS
The hardware synthesiser of the EZMIDI IOP module, from midi_hsyn.c.
Definition hsyn.h:17
#define HSYN_BANKS
Bank slots of gaHds and gaBds.
Definition hsyn.h:20
int HardSynthSetRemix(int parm)
Switch remix mode.
int StartAutoDMA(void *pIOP, void *pSPU, int iDirection)
Start an automatic DMA stream.
unsigned char * gpHd
Bank header of the note being started.
int HardSynthSetMono(int parm)
Switch mono output and recompute every channel.
void HardSynthAllNotesOff(int iChan, int do_now)
Silence the notes of a channel.
int hs_update_note_and_fx(sSynNote *pNote)
Apply one tick of channel changes, chorus, and volume slides to a note.
void _init_channels(void)
Reset every channel to its default MIDI state.
The tick timer.
Definition hsyn.h:105
int thread_id
Definition hsyn.h:106
int count
Definition hsyn.h:108
int timer_id
Definition hsyn.h:107
A table chunk of a bank header.
Definition hsyn.h:121
int offsets[]
Definition hsyn.h:124
unsigned char reserved[12]
Definition hsyn.h:122
int maxIndex
Definition hsyn.h:123
Bank header.
Definition hsyn.h:112
int programChunk
Definition hsyn.h:114
unsigned char reserved[36]
Definition hsyn.h:113
int vagInfoChunk
Definition hsyn.h:117
int sampleChunk
Definition hsyn.h:116
int sampleSetChunk
Definition hsyn.h:115
A program record.
Definition hsyn.h:141
unsigned char splitCount
Definition hsyn.h:143
sHdSplit split[]
Definition hsyn.h:150
unsigned char reserved[26]
Definition hsyn.h:149
unsigned char volume
Definition hsyn.h:145
signed char detune
Definition hsyn.h:148
unsigned char pan
Definition hsyn.h:146
signed char transpose
Definition hsyn.h:147
unsigned char reserved5
Definition hsyn.h:144
unsigned char reserved0[4]
Definition hsyn.h:142
A sample set record.
Definition hsyn.h:154
unsigned char reserved[4]
Definition hsyn.h:155
unsigned short sampleIndex[]
Definition hsyn.h:156
A sample record.
Definition hsyn.h:160
unsigned char volume
Definition hsyn.h:167
unsigned char reserved12
Definition hsyn.h:164
unsigned char baseNote
Definition hsyn.h:163
unsigned short adsr1
Definition hsyn.h:169
unsigned char reserved2[9]
Definition hsyn.h:162
unsigned char reserved22[19]
Definition hsyn.h:171
short vagIndex
Definition hsyn.h:161
unsigned char spuAttr
Definition hsyn.h:172
unsigned char reserved17
Definition hsyn.h:168
unsigned char pan
Definition hsyn.h:165
unsigned short adsr2
Definition hsyn.h:170
unsigned char reserved14[2]
Definition hsyn.h:166
A key split of a program.
Definition hsyn.h:128
unsigned char reserved5[11]
Definition hsyn.h:133
unsigned char rangeLow
Definition hsyn.h:130
unsigned char reserved3
Definition hsyn.h:131
signed char detune
Definition hsyn.h:137
unsigned char rangeHigh
Definition hsyn.h:132
unsigned char pan
Definition hsyn.h:135
signed char transpose
Definition hsyn.h:136
unsigned char volume
Definition hsyn.h:134
unsigned short sampleSetIndex
Definition hsyn.h:129
A VAG information record.
Definition hsyn.h:176
unsigned int offset
Definition hsyn.h:177
unsigned short sampleRate
Definition hsyn.h:178
unsigned char attribute
Definition hsyn.h:179
Per-channel MIDI state.
Definition hsyn.h:58
unsigned char iFx
Definition hsyn.h:67
unsigned short iPitch
Definition hsyn.h:65
unsigned char iPadc
Definition hsyn.h:69
unsigned short iMod
Definition hsyn.h:64
unsigned short iPads
Definition hsyn.h:70
unsigned char iPan
Definition hsyn.h:61
unsigned char iVol
Definition hsyn.h:60
unsigned char iBankHi
Definition hsyn.h:66
unsigned char iPri
Definition hsyn.h:68
unsigned char iProg
Definition hsyn.h:59
unsigned short iBank
Definition hsyn.h:63
unsigned char iExp
Definition hsyn.h:62
One sounding note and the voice that plays it.
Definition hsyn.h:74
unsigned char i_pad
Definition hsyn.h:84
unsigned short chr_idx
Definition hsyn.h:88
unsigned short t_vol[2]
Definition hsyn.h:87
unsigned char bank
Definition hsyn.h:93
unsigned short i_pitch
Definition hsyn.h:82
unsigned char fx
Definition hsyn.h:80
unsigned char i_pan
Definition hsyn.h:83
unsigned short c_pitch
Definition hsyn.h:85
unsigned short c_vol[2]
Definition hsyn.h:86
unsigned char slot
Definition hsyn.h:77
unsigned char pri
Definition hsyn.h:92
unsigned short i_vol
Definition hsyn.h:81
unsigned char slave
Definition hsyn.h:78
unsigned char pada[6]
Definition hsyn.h:94
unsigned char chan
Definition hsyn.h:75
unsigned short stt_targ[2]
Definition hsyn.h:90
unsigned char flag
Definition hsyn.h:79
unsigned char note
Definition hsyn.h:76
unsigned char stt_frame[2]
Definition hsyn.h:91
unsigned short chr_rng
Definition hsyn.h:89
Synthesiser settings the EE sends with HardSynthConfig().
Definition ezmidi.h:57
Run-time switches the EE sets.
Definition hsyn.h:98
unsigned char remix_mode
Definition hsyn.h:100
unsigned char mono_mode
Definition hsyn.h:101
unsigned short run_chr_rate[2]
Definition hsyn.h:99