PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
libsd-common.h
Go to the documentation of this file.
1
6#ifndef __LIBSD_COMMON_H__
7#define __LIBSD_COMMON_H__
8
9#include <tamtypes.h>
10
11#define SD_VOICE(_core, _v) ((_core) | ((_v) << 1))
12
13/* Macros to set ADSR: i=increment, d=decrement */
14#define SD_ADSR_AR_LINEARi 0
15#define SD_ADSR_AR_EXPi 1
16#define SD_ADSR_SR_LINEARi 0
17#define SD_ADSR_SR_LINEARd 2
18#define SD_ADSR_SR_EXPi 4
19#define SD_ADSR_SR_EXPd 6
20#define SD_ADSR_RR_LINEARd 0
21#define SD_ADSR_RR_EXPd 1
22#define SD_SET_ADSR1(_arm, _ar, _dr, _sl) ((((_arm)&1) << 15) | (((_ar)&0x7f) << 8) | (((_dr)&0xf) << 4) | ((_sl)&0xf))
23#define SD_SET_ADSR2(_srm, _sr, _rrm, _rr) ((((_srm)&7) << 13) | (((_sr)&0x7f) << 6) | (((_rrm)&1) << 5) | ((_rr)&0x1f))
24
25/* Parameters */
26#define SD_VPARAM_VOLL (0x00 << 8)
27#define SD_VPARAM_VOLR (0x01 << 8)
28#define SD_VPARAM_PITCH (0x02 << 8)
29#define SD_VPARAM_ADSR1 (0x03 << 8)
30#define SD_VPARAM_ADSR2 (0x04 << 8)
31#define SD_VPARAM_ENVX (0x05 << 8)
32#define SD_VPARAM_VOLXL (0x06 << 8)
33#define SD_VPARAM_VOLXR (0x07 << 8)
34#define SD_PARAM_MMIX (0x08 << 8)
35#define SD_PARAM_MVOLL ((0x09 << 8) | 0x80)
36#define SD_PARAM_MVOLR ((0x0A << 8) | 0x80)
37#define SD_PARAM_EVOLL ((0x0B << 8) | 0x80)
38#define SD_PARAM_EVOLR ((0x0C << 8) | 0x80)
39#define SD_PARAM_AVOLL ((0x0D << 8) | 0x80)
40#define SD_PARAM_AVOLR ((0x0E << 8) | 0x80)
41#define SD_PARAM_BVOLL ((0x0F << 8) | 0x80)
42#define SD_PARAM_BVOLR ((0x10 << 8) | 0x80)
43#define SD_PARAM_MVOLXL ((0x11 << 8) | 0x80)
44#define SD_PARAM_MVOLXR ((0x12 << 8) | 0x80)
45
46/* Transfer modes */
47#define SD_TRANS_WRITE 0
48#define SD_TRANS_READ 1
49#define SD_TRANS_STOP 2
50#define SD_TRANS_WRITE_FROM 3 /* only for block */
51#define SD_TRANS_LOOP 0x10 /* only for block*/
52#define SD_TRANS_MODE_DMA 0
53#define SD_TRANS_MODE_IO 8
54
55// Reverb
56#define SD_EFFECT_MODE_OFF 0x0
57#define SD_EFFECT_MODE_ROOM 0x1
58#define SD_EFFECT_MODE_STUDIO_1 0x2
59#define SD_EFFECT_MODE_STUDIO_2 0x3
60#define SD_EFFECT_MODE_STUDIO_3 0x4
61#define SD_EFFECT_MODE_HALL 0x5
62#define SD_EFFECT_MODE_SPACE 0x6
63#define SD_EFFECT_MODE_ECHO 0x7
64#define SD_EFFECT_MODE_DELAY 0x8
65#define SD_EFFECT_MODE_PIPE 0x9
66#define SD_EFFECT_MODE_CLEAR 0x100
67
68// CoreAttr
69#define SD_CORE_EFFECT_ENABLE 0x2
70#define SD_CORE_IRQ_ENABLE 0x4
71#define SD_CORE_MUTE_ENABLE 0x6
72#define SD_CORE_NOISE_CLK 0x8
73#define SD_CORE_SPDIF_MODE 0xA
74
75/* Switches */
76#define SD_SWITCH_PMON (0x13 << 8)
77#define SD_SWITCH_NON (0x14 << 8)
78#define SD_SWITCH_KON (0x15 << 8)
79#define SD_SWITCH_KEYDOWN SD_SWITCH_KON // For backward-compatibility
80#define SD_SWITCH_KOFF (0x16 << 8)
81#define SD_SWITCH_KEYUP SD_SWITCH_KOFF // For backward-compatibility
82#define SD_SWITCH_ENDX (0x17 << 8)
83#define SD_SWITCH_VMIXL (0x18 << 8)
84#define SD_SWITCH_VMIXEL (0x19 << 8)
85#define SD_SWITCH_VMIXR (0x1A << 8)
86#define SD_SWITCH_VMIXER (0x1B << 8)
87
88/* Addresses */
89#define SD_ADDR_ESA (0x1C << 8)
90#define SD_ADDR_EEA (0x1D << 8)
91#define SD_ADDR_TSA (0x1E << 8)
92#define SD_ADDR_IRQA (0x1F << 8)
93#define SD_VADDR_SSA (0x20 << 8)
94#define SD_VADDR_LSAX (0x21 << 8)
95#define SD_VADDR_NAX (0x22 << 8)
96
97// SD_CORE_ATTR Macros
98#define SD_SPU2_ON (1 << 15)
99#define SD_MUTE (1 << 14)
100#define SD_NOISE_CLOCK(c) ((c & 0x1F) << 8) // Bits 8..13 is noise clock
101#define SD_ENABLE_EFFECTS (1 << 7)
102#define SD_ENABLE_IRQ (1 << 6)
103#define SD_DMA_IO (1 << 4)
104#define SD_DMA_WRITE (2 << 4)
105#define SD_DMA_READ (3 << 4)
106#define SD_DMA_IN_PROCESS (3 << 4) // If either of the DMA bits are set, the DMA channel is occupied.
107#define SD_CORE_DMA (3 << 4)
108#define SD_ENABLE_EX_INPUT (1 << 0) // Enable external input, Not sure.
109
110// SD_C_STATX
111#define SD_IO_IN_PROCESS (1 << 10)
112
113// Batch
114#define SD_BATCH_SETPARAM 0x1
115#define SD_BATCH_SETSWITCH 0x2
116#define SD_BATCH_SETADDR 0x3
117#define SD_BATCH_SETCORE 0x4
118#define SD_BATCH_WRITEIOP 0x5
119#define SD_BATCH_WRITEEE 0x6
120#define SD_BATCH_EERETURN 0x7
121#define SD_BATCH_GETPARAM 0x10
122#define SD_BATCH_GETSWITCH 0x12
123#define SD_BATCH_GETADDR 0x13
124#define SD_BATCH_GETCORE 0x14
125
126#define ADPCM_LOOP_START 4 /* Set on first block of looped data */
127#define ADPCM_LOOP 2 /* Set on all blocks (?that are inside the loop?) */
128#define ADPCM_LOOP_END 1 /* Set on last block to loop */
129
130typedef struct
131{
132 u16 func;
133 u16 entry;
134 u32 value;
135} sceSdBatch;
136
137typedef struct
138{
139 int core;
140 int mode;
141 short depth_L;
142 short depth_R;
143 int delay;
144 int feedback;
146
147typedef int (*sceSdSpu2IntrHandler)(int, void *);
148typedef int (*sceSdTransIntrHandler)(int, void *);
149typedef int (*SdIntrCallback)(void *data);
150
151#ifdef __cplusplus
152extern "C" {
153#endif
154
155int sceSdQuit();
156int sceSdInit(int flag);
157SdIntrCallback sceSdSetIRQCallback(SdIntrCallback cb);
158SdIntrCallback sceSdSetTransCallback(s32 core, SdIntrCallback cb);
159
160void sceSdSetParam(u16 entry, u16 value);
161u16 sceSdGetParam(u16 entry);
162
163void sceSdSetCoreAttr(u16 entry, u16 value);
164u16 sceSdGetCoreAttr(u16 entry);
165int sceSdClearEffectWorkArea(int core, int channel, int effect_mode);
166
167void sceSdSetAddr(u16 entry, u32 value);
168u32 sceSdGetAddr(u16 entry);
169
170void sceSdSetSwitch(u16 entry, u32 value);
171u32 sceSdGetSwitch(u16 entry);
172
173u16 sceSdNote2Pitch(u16 center_note, u16 center_fine, u16 note, s16 fine);
174u16 sceSdPitch2Note(u16 center_note, u16 center_fine, u16 pitch);
175
176int sceSdSetEffectAttr(int core, sceSdEffectAttr *attr);
177void sceSdGetEffectAttr(int core, sceSdEffectAttr *attr);
178
179int sceSdProcBatch(sceSdBatch *batch, u32 *rets, u32 num);
180int sceSdProcBatchEx(sceSdBatch *batch, u32 *rets, u32 num, u32 voice);
181
182int sceSdVoiceTrans(s16 chan, u16 mode, u8 *iopaddr, u32 *spuaddr, u32 size);
183int sceSdBlockTrans(s16 chan, u16 mode, u8 *iopaddr, u32 size, ...);
184u32 sceSdVoiceTransStatus(s16 channel, s16 flag);
185u32 sceSdBlockTransStatus(s16 channel, s16 flag);
186
187sceSdTransIntrHandler sceSdSetTransIntrHandler(int channel, sceSdTransIntrHandler func, void *arg);
188sceSdSpu2IntrHandler sceSdSetSpu2IntrHandler(sceSdSpu2IntrHandler func, void *arg);
189
190void *sceSdGetTransIntrHandlerArgument(int arg);
191void *sceSdGetSpu2IntrHandlerArgument();
192int sceSdStopTrans(int channel);
193int sceSdCleanEffectWorkArea(int core, int channel, int effect_mode);
194int sceSdSetEffectMode(int core, sceSdEffectAttr *param);
195int sceSdSetEffectModeParams(int core, sceSdEffectAttr *attr);
196
197#ifdef __cplusplus
198}
199#endif
200
201// Backwards compatibility definitions
202#define BATCH_SETPARAM SD_BATCH_SETPARAM
203#define BATCH_SETSWITCH SD_BATCH_SETSWITCH
204#define BATCH_SETADDR SD_BATCH_SETADDR
205#define BATCH_SETCORE SD_BATCH_SETCORE
206#define BATCH_WRITEIOP SD_BATCH_WRITEIOP
207#define BATCH_WRITEEE SD_BATCH_WRITEEE
208#define BATCH_EERETURN SD_BATCH_EERETURN
209#define BATCH_GETPARAM SD_BATCH_GETPARAM
210#define BATCH_GETSWITCH SD_BATCH_GETSWITCH
211#define BATCH_GETADDR SD_BATCH_GETADDR
212#define BATCH_GETCORE SD_BATCH_GETCORE
213
214#define SD_BLOCK_TRANS_WRITE SD_TRANS_WRITE
215#define SD_BLOCK_TRANS_READ SD_TRANS_READ
216#define SD_BLOCK_TRANS_STOP SD_TRANS_STOP
217#define SD_BLOCK_TRANS_WRITE_FROM SD_TRANS_WRITE_FROM
218#define SD_BLOCK_TRANS_LOOP SD_TRANS_LOOP
219
220#define SD_VOICE_TRANS_WRITE SD_TRANS_WRITE
221#define SD_VOICE_TRANS_READ SD_TRANS_READ
222#define SD_VOICE_TRANS_STOP SD_TRANS_STOP
223#define SD_VOICE_TRANS_MODE_DMA SD_TRANS_MODE_DMA
224#define SD_VOICE_TRANS_MODE_IO SD_TRANS_MODE_IO
225
226#define SdBatch sceSdBatch
227#define SdEffectAttr sceSdEffectAttr
228#define SdSpu2IntrHandler sceSdSpu2IntrHandler
229#define SdTransIntrHandler sceSdTransIntrHandler
230#define IntrCallback SdIntrCallback
231
232#define SdQuit sceSdQuit
233#define SdInit sceSdInit
234#define SdSetIRQCallback sceSdSetIRQCallback
235#define SdSetTransCallback sceSdSetTransCallback
236#define SdSetParam sceSdSetParam
237#define SdGetParam sceSdGetParam
238#define SdSetCoreAttr sceSdSetCoreAttr
239#define SdGetCoreAttr sceSdGetCoreAttr
240#define SdClearEffectWorkArea sceSdClearEffectWorkArea
241#define SdSetAddr sceSdSetAddr
242#define SdGetAddr sceSdGetAddr
243#define SdSetSwitch sceSdSetSwitch
244#define SdGetSwitch sceSdGetSwitch
245#define SdNote2Pitch sceSdNote2Pitch
246#define SdPitch2Note sceSdPitch2Note
247#define SdSetEffectAttr sceSdSetEffectAttr
248#define SdGetEffectAttr sceSdGetEffectAttr
249#define SdProcBatch sceSdProcBatch
250#define SdProcBatchEx sceSdProcBatchEx
251#define SdVoiceTrans sceSdVoiceTrans
252#define SdBlockTrans sceSdBlockTrans
253#define SdVoiceTransStatus sceSdVoiceTransStatus
254#define SdBlockTransStatus sceSdBlockTransStatus
255#define SdSetTransIntrHandler sceSdSetTransIntrHandler
256#define SdSetSpu2IntrHandler sceSdSetSpu2IntrHandler
257#define SdGetTransIntrHandlerArgument sceSdGetTransIntrHandlerArgument
258#define SdGetSpu2IntrHandlerArgument sceSdGetSpu2IntrHandlerArgument
259#define SdStopTrans sceSdStopTrans
260#define SdCleanEffectWorkArea sceSdCleanEffectWorkArea
261#define SdSetEffectMode sceSdSetEffectMode
262#define SdSetEffectModeParams sceSdSetEffectModeParams
263
264#endif /* __LIBSD_COMMON_H__ */