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