PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ps2snd.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2005, James Lee (jbit<at>jbit<dot>net)
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include <string.h>
12#include <kernel.h>
13#include <sifrpc.h>
14#include <iopheap.h>
15#include <stdio.h>
16#include <ps2snd.h>
17
18static SifRpcClientData_t sd_client ALIGNED(64);
19
20int sceSdInit(int flag)
21{
22 s32 buf[1] ALIGNED(64);
23
24 {
25
26 while(1)
27 {
28 if (SifBindRpc(&sd_client, BINDID_PS2SND, 0) < 0)
29 {
30 printf("%s: Failed to bind to rpc '0x%08x'\n", __FUNCTION__, BINDID_PS2SND);
31 return(-1);
32 }
33
34 if (sd_client.server != NULL)
35 break;
36
37 nopdelay();
38 }
39
40 }
41
42 buf[0] = flag;
43 SifCallRpc(&sd_client, PS2SND_Init, 0, buf, 4, buf, 4, NULL, NULL);
44
45 return(buf[0]);
46}
47
48void sceSdSetParam(u16 entry, u16 value)
49{
50 u32 buf[2] ALIGNED(64);
51 buf[0] = entry;
52 buf[1] = value;
53 SifCallRpc(&sd_client, PS2SND_SetParam, 0, buf, 8, NULL, 0, NULL, NULL);
54}
55
56u16 sceSdGetParam(u16 entry)
57{
58 u32 buf[1] ALIGNED(64);
59 buf[0] = entry;
60 SifCallRpc(&sd_client, PS2SND_GetParam, 0, buf, 4, buf, 4, NULL, NULL);
61 return(buf[0]);
62}
63
64void sceSdSetSwitch(u16 entry, u32 value)
65{
66 u32 buf[2] ALIGNED(64);
67 buf[0] = entry;
68 buf[1] = value;
69 SifCallRpc(&sd_client, PS2SND_SetSwitch, 0, buf, 8, NULL, 0, NULL, NULL);
70}
71
72u32 sceSdGetSwitch(u16 entry)
73{
74 u32 buf[1] ALIGNED(64);
75 buf[0] = entry;
76 SifCallRpc(&sd_client, PS2SND_GetSwitch, 0, buf, 4, buf, 4, NULL, NULL);
77 return(buf[0]);
78}
79
80void sceSdSetAddr(u16 entry, u32 value)
81{
82 u32 buf[2] ALIGNED(64);
83 buf[0] = entry;
84 buf[1] = value;
85 SifCallRpc(&sd_client, PS2SND_SetAddr, 0, buf, 8, NULL, 0, NULL, NULL);
86}
87
88u32 sceSdGetAddr(u16 entry)
89{
90 u32 buf[1] ALIGNED(64);
91 buf[0] = entry;
92 SifCallRpc(&sd_client, PS2SND_GetAddr, 0, buf, 4, buf, 4, NULL, NULL);
93 return(buf[0]);
94}
95
96void sceSdSetCoreAttr(u16 entry, u16 value)
97{
98 u32 buf[2] ALIGNED(64);
99 buf[0] = entry;
100 buf[1] = value;
101 SifCallRpc(&sd_client, PS2SND_SetCoreAttr, 0, buf, 8, NULL, 0, NULL, NULL);
102}
103
104u16 sceSdGetCoreAttr(u16 entry)
105{
106 u32 buf[1] ALIGNED(64);
107 buf[0] = entry;
108 SifCallRpc(&sd_client, PS2SND_GetCoreAttr, 0, buf, 4, buf, 4, NULL, NULL);
109 return(buf[0]);
110}
111
112u16 sceSdNote2Pitch(u16 center_note, u16 center_fine, u16 note, s16 fine)
113{
114 (void)center_note;
115 (void)center_fine;
116 (void)note;
117 (void)fine;
118
119 /* TODO: These functions were documented for the ps1 once... */
120 return(0);
121}
122
123u16 sceSdPitch2Note(u16 center_note, u16 center_fine, u16 pitch)
124{
125 (void)center_note;
126 (void)center_fine;
127 (void)pitch;
128
129 /* TODO: These functions were documented for the ps1 once... */
130 return(0);
131}
132
133int sceSdProcBatch(sceSdBatch* batch, u32 returns[], u32 num)
134{
135 (void)batch;
136 (void)returns;
137 (void)num;
138
139 /* TODO */
140 return(-1);
141}
142
143int sceSdProcBatchEx(sceSdBatch* batch, u32 returns[], u32 num, u32 voice)
144{
145 (void)batch;
146 (void)returns;
147 (void)num;
148 (void)voice;
149
150 /* TODO */
151 return(-1);
152}
153
154
155int sceSdVoiceTrans(s16 channel, u16 mode, u8 *m_addr, u32 *s_addr, u32 size)
156{
157 u32 buf[5] ALIGNED(64);
158 ((s32 *)buf)[0] = channel;
159 buf[1] = mode;
160 buf[2] = (u32)m_addr;
161 buf[3] = (u32)s_addr;
162 buf[4] = size;
163
164 SifCallRpc(&sd_client, PS2SND_VoiceTrans, 0, buf, 20, buf, 4, NULL, NULL);
165 return(((s32 *)buf)[0]);
166}
167
168int sceSdBlockTrans(s16 channel, u16 mode, u8 *m_addr, u32 size, ...)
169{
170 (void)channel;
171 (void)mode;
172 (void)m_addr;
173 (void)size;
174
175 return(-1);
176}
177
178u32 sceSdVoiceTransStatus (s16 channel, s16 flag)
179{
180 s32 buf[2] ALIGNED(64);
181 buf[0] = channel;
182 buf[1] = flag;
183
184 SifCallRpc(&sd_client, PS2SND_VoiceTransStatus, 0, buf, 8, buf, 4, NULL, NULL);
185 return(((u32 *)buf)[0]);
186}
187
188u32 sceSdBlockTransStatus (s16 channel, s16 flag)
189{
190 s32 buf[2] ALIGNED(64);
191 buf[0] = channel;
192 buf[1] = flag;
193
194 SifCallRpc(&sd_client, PS2SND_BlockTransStatus, 0, buf, 8, buf, 4, NULL, NULL);
195 return(((u32 *)buf)[0]);
196}
197
198//void* sceSdSetTransCallback (u16 channel, void SD_TRANS_CBProc(void *) );
199//void *sceSdSetIRQCallback( void SD_IRQ_CBProc(void *) );
200
201int sceSdSetEffectAttr (int core, sceSdEffectAttr *attr)
202{
203 s32 buf[1+((sizeof(sceSdEffectAttr)+3)/4)] ALIGNED(64);
204 buf[0] = core;
205 memcpy(&buf[1], attr, sizeof(sceSdEffectAttr));
206 SifCallRpc(&sd_client, PS2SND_SetEffectAttr, 0, buf, 4+sizeof(sceSdEffectAttr), buf, 4, NULL, NULL);
207 return(buf[0]);
208}
209
210void sceSdGetEffectAttr (int core, sceSdEffectAttr *attr)
211{
212 s32 buf[((sizeof(sceSdEffectAttr)+3)/4)] ALIGNED(64);
213 buf[0] = core;
214 SifCallRpc(&sd_client, PS2SND_GetEffectAttr, 0, buf, 4, buf, sizeof(sceSdEffectAttr), NULL, NULL);
215 memcpy(attr, buf, sizeof(sceSdEffectAttr));
216}
217
218int sceSdClearEffectWorkArea (int core, int channel, int effect_mode)
219{
220 s32 buf[3] ALIGNED(64);
221 buf[0] = core;
222 buf[1] = channel;
223 buf[2] = effect_mode;
224 SifCallRpc(&sd_client, PS2SND_ClearEffectWorkArea, 0, buf, 12, buf, 4, NULL, NULL);
225 return(buf[0]);
226}
227
228
229u32 sndQueryMaxFreeMemSize(void)
230{
231 u32 buf[1] ALIGNED(64);
232 SifCallRpc(&sd_client, PS2SND_QueryMaxFreeMemSize, 0, NULL, 0, buf, 4, NULL, NULL);
233 return(buf[0]);
234}
235
236int sndStreamOpen(char *file, u32 voices, u32 flags, u32 bufaddr, u32 bufsize)
237{
238 u32 buf[32] ALIGNED(64);
239 buf[0] = voices;
240 buf[1] = flags;
241 buf[2] = bufaddr;
242 buf[3] = bufsize;
243 strncpy((char*)&buf[4], file, 27*4);
244 buf[31] = 0;
245
246 SifCallRpc(&sd_client, PS2SND_StreamOpen, 0, buf, 128, buf, 4, NULL, NULL);
247 return(((s32 *)buf)[0]);
248}
249
250
251int sndStreamClose(void)
252{
253 s32 buf[1] ALIGNED(64);
254 SifCallRpc(&sd_client, PS2SND_StreamClose, 0, NULL, 0, buf, 4, NULL, NULL);
255 return(buf[0]);
256}
257
258int sndStreamPlay(void)
259{
260 s32 buf[1] ALIGNED(64);
261 SifCallRpc(&sd_client, PS2SND_StreamPlay, 0, NULL, 0, buf, 4, NULL, NULL);
262 return(buf[0]);
263}
264
265
266int sndStreamPause(void)
267{
268 s32 buf[1] ALIGNED(64);
269 SifCallRpc(&sd_client, PS2SND_StreamPause, 0, NULL, 0, buf, 4, NULL, NULL);
270 return(buf[0]);
271}
272
273int sndStreamSetPosition(int block)
274{
275 s32 buf[1] ALIGNED(64);
276 buf[0] = block;
277 SifCallRpc(&sd_client, PS2SND_StreamSetPosition, 0, buf, 4, buf, 4, NULL, NULL);
278 return(buf[0]);
279}
280
281int sndStreamSetVolume(int left, int right)
282{
283 s32 buf[2] ALIGNED(64);
284 buf[0] = left;
285 buf[1] = right;
286 SifCallRpc(&sd_client, PS2SND_StreamSetVolume, 0, buf, 8, buf, 4, NULL, NULL);
287 return(buf[0]);
288}
289
290int sndStreamGetPosition(void)
291{
292 s32 buf[1] ALIGNED(64);
293 SifCallRpc(&sd_client, PS2SND_StreamGetPosition, 0, NULL, 0, buf, 4, NULL, NULL);
294 return(buf[0]);
295}
296
297int sndLoadSample(void *buf, u32 spuaddr, int size)
298{
299 void *iopbuf;
300 int id, iopfree;
301 SifDmaTransfer_t sifdma;
302
303 iopfree = sndQueryMaxFreeMemSize()/2;
304 if (size>iopfree)
305 {
306 return(-1);
307 }
308
309 iopbuf = SifAllocIopHeap(size);
310 if (iopbuf==0)
311 return(-1);
312
313 FlushCache(0);
314
315 sifdma.src = buf;
316 sifdma.dest = iopbuf;
317 sifdma.size = size;
318 sifdma.attr = 0;
319
320 id = SifSetDma(&sifdma, 1);
321 while(SifDmaStat(id) >= 0);;
322 FlushCache(0);
323
324 sceSdVoiceTrans(0, SD_TRANS_WRITE, iopbuf, (void*)spuaddr, size);
325 sceSdVoiceTransStatus(0, 1);
326
327 SifFreeIopHeap(iopbuf);
328
329 return(size);
330}