ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
ps2snd.c File Reference
#include <string.h>
#include <kernel.h>
#include <sifrpc.h>
#include <iopheap.h>
#include <stdio.h>
#include <ps2snd.h>
+ Include dependency graph for ps2snd.c:

Go to the source code of this file.

Functions

int sceSdInit (int flag)
 
void sceSdSetParam (u16 entry, u16 value)
 
u16 sceSdGetParam (u16 entry)
 
void sceSdSetSwitch (u16 entry, u32 value)
 
u32 sceSdGetSwitch (u16 entry)
 
void sceSdSetAddr (u16 entry, u32 value)
 
u32 sceSdGetAddr (u16 entry)
 
void sceSdSetCoreAttr (u16 entry, u16 value)
 
u16 sceSdGetCoreAttr (u16 entry)
 
u16 sceSdNote2Pitch (u16 center_note, u16 center_fine, u16 note, s16 fine)
 
u16 sceSdPitch2Note (u16 center_note, u16 center_fine, u16 pitch)
 
int sceSdProcBatch (sceSdBatch *batch, u32 returns[], u32 num)
 
int sceSdProcBatchEx (sceSdBatch *batch, u32 returns[], u32 num, u32 voice)
 
int sceSdVoiceTrans (s16 channel, u16 mode, u8 *m_addr, u32 *s_addr, u32 size)
 
int sceSdBlockTrans (s16 channel, u16 mode, u8 *m_addr, u32 size,...)
 
u32 sceSdVoiceTransStatus (s16 channel, s16 flag)
 
u32 sceSdBlockTransStatus (s16 channel, s16 flag)
 
int sceSdSetEffectAttr (int core, sceSdEffectAttr *attr)
 
void sceSdGetEffectAttr (int core, sceSdEffectAttr *attr)
 
int sceSdClearEffectWorkArea (int core, int channel, int effect_mode)
 
u32 sndQueryMaxFreeMemSize (void)
 
int sndStreamOpen (char *file, u32 voices, u32 flags, u32 bufaddr, u32 bufsize)
 
int sndStreamClose (void)
 
int sndStreamPlay (void)
 
int sndStreamPause (void)
 
int sndStreamSetPosition (int block)
 
int sndStreamSetVolume (int left, int right)
 
int sndStreamGetPosition (void)
 
int sndLoadSample (void *buf, u32 spuaddr, int size)
 

Variables

static SifRpcClientData_t sd_client
 
static int sd_started = 0
 

Function Documentation

◆ sceSdBlockTrans()

int sceSdBlockTrans ( s16  channel,
u16  mode,
u8 m_addr,
u32  size,
  ... 
)

Definition at line 152 of file ps2snd.c.

153 {
154  return(-1);
155 }

◆ sceSdBlockTransStatus()

u32 sceSdBlockTransStatus ( s16  channel,
s16  flag 
)

Definition at line 167 of file ps2snd.c.

168 {
169  s32 buf[2] ALIGNED(64);
170  buf[0] = channel;
171  buf[1] = flag;
172 
173  SifCallRpc(&sd_client, PS2SND_BlockTransStatus, 0, buf, 8, buf, 4, NULL, NULL);
174  return(((u32 *)buf)[0]);
175 }
#define ALIGNED(x)
Definition: kernel.h:50
static SifRpcClientData_t sd_client
Definition: ps2snd.c:18
#define PS2SND_BlockTransStatus
Definition: ps2snd.h:44
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
#define NULL
Definition: tamtypes.h:91
signed int s32
Definition: tamtypes.h:58
unsigned int u32
Definition: tamtypes.h:30

References ALIGNED, NULL, PS2SND_BlockTransStatus, sd_client, and SifCallRpc().

◆ sceSdClearEffectWorkArea()

int sceSdClearEffectWorkArea ( int  core,
int  channel,
int  effect_mode 
)

Definition at line 197 of file ps2snd.c.

198 {
199  s32 buf[3] ALIGNED(64);
200  buf[0] = core;
201  buf[1] = channel;
202  buf[2] = effect_mode;
203  SifCallRpc(&sd_client, PS2SND_ClearEffectWorkArea, 0, buf, 12, buf, 4, NULL, NULL);
204  return(buf[0]);
205 }
#define PS2SND_ClearEffectWorkArea
Definition: ps2snd.h:49

References ALIGNED, NULL, PS2SND_ClearEffectWorkArea, sd_client, and SifCallRpc().

◆ sceSdGetAddr()

u32 sceSdGetAddr ( u16  entry)

Definition at line 90 of file ps2snd.c.

91 {
92  u32 buf[1] ALIGNED(64);
93  buf[0] = entry;
94  SifCallRpc(&sd_client, PS2SND_GetAddr, 0, buf, 4, buf, 4, NULL, NULL);
95  return(buf[0]);
96 }
#define PS2SND_GetAddr
Definition: ps2snd.h:34

References ALIGNED, NULL, PS2SND_GetAddr, sd_client, and SifCallRpc().

◆ sceSdGetCoreAttr()

u16 sceSdGetCoreAttr ( u16  entry)

Definition at line 106 of file ps2snd.c.

107 {
108  u32 buf[1] ALIGNED(64);
109  buf[0] = entry;
110  SifCallRpc(&sd_client, PS2SND_GetCoreAttr, 0, buf, 4, buf, 4, NULL, NULL);
111  return(buf[0]);
112 }
#define PS2SND_GetCoreAttr
Definition: ps2snd.h:36

References ALIGNED, NULL, PS2SND_GetCoreAttr, sd_client, and SifCallRpc().

◆ sceSdGetEffectAttr()

void sceSdGetEffectAttr ( int  core,
sceSdEffectAttr attr 
)

Definition at line 189 of file ps2snd.c.

190 {
191  s32 buf[((sizeof(sceSdEffectAttr)+3)/4)] ALIGNED(64);
192  buf[0] = core;
193  SifCallRpc(&sd_client, PS2SND_GetEffectAttr, 0, buf, 4, buf, sizeof(sceSdEffectAttr), NULL, NULL);
194  memcpy(attr, buf, sizeof(sceSdEffectAttr));
195 }
#define PS2SND_GetEffectAttr
Definition: ps2snd.h:48

References ALIGNED, NULL, PS2SND_GetEffectAttr, sd_client, and SifCallRpc().

◆ sceSdGetParam()

u16 sceSdGetParam ( u16  entry)

Definition at line 58 of file ps2snd.c.

59 {
60  u32 buf[1] ALIGNED(64);
61  buf[0] = entry;
62  SifCallRpc(&sd_client, PS2SND_GetParam, 0, buf, 4, buf, 4, NULL, NULL);
63  return(buf[0]);
64 }
#define PS2SND_GetParam
Definition: ps2snd.h:30

References ALIGNED, NULL, PS2SND_GetParam, sd_client, and SifCallRpc().

◆ sceSdGetSwitch()

u32 sceSdGetSwitch ( u16  entry)

Definition at line 74 of file ps2snd.c.

75 {
76  u32 buf[1] ALIGNED(64);
77  buf[0] = entry;
78  SifCallRpc(&sd_client, PS2SND_GetSwitch, 0, buf, 4, buf, 4, NULL, NULL);
79  return(buf[0]);
80 }
#define PS2SND_GetSwitch
Definition: ps2snd.h:32

References ALIGNED, NULL, PS2SND_GetSwitch, sd_client, and SifCallRpc().

◆ sceSdInit()

int sceSdInit ( int  flag)

Definition at line 21 of file ps2snd.c.

22 {
23  s32 buf[1] ALIGNED(64);
24 
25  if (!sd_started)
26  {
27 
28  while(1)
29  {
30  if (SifBindRpc(&sd_client, BINDID_PS2SND, 0) < 0)
31  {
32  printf("%s: Failed to bind to rpc '0x%08x'\n", __FUNCTION__, BINDID_PS2SND);
33  return(-1);
34  }
35 
36  if (sd_client.server != NULL)
37  break;
38 
39  nopdelay();
40  }
41 
42  }
43 
44  buf[0] = flag;
45  SifCallRpc(&sd_client, PS2SND_Init, 0, buf, 4, buf, 4, NULL, NULL);
46 
47  return(buf[0]);
48 }
static void nopdelay(void)
Definition: kernel.h:141
static int sd_started
Definition: ps2snd.c:19
#define BINDID_PS2SND
Definition: ps2snd.h:26
#define PS2SND_Init
Definition: ps2snd.h:28
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142

References ALIGNED, BINDID_PS2SND, nopdelay(), NULL, PS2SND_Init, sd_client, sd_started, SifRpcClientData_t::server, SifBindRpc(), and SifCallRpc().

Referenced by main().

◆ sceSdNote2Pitch()

u16 sceSdNote2Pitch ( u16  center_note,
u16  center_fine,
u16  note,
s16  fine 
)

Definition at line 114 of file ps2snd.c.

115 {
116  /* TODO: These functions were documented for the ps1 once... */
117  return(0);
118 }

◆ sceSdPitch2Note()

u16 sceSdPitch2Note ( u16  center_note,
u16  center_fine,
u16  pitch 
)

Definition at line 120 of file ps2snd.c.

121 {
122  /* TODO: These functions were documented for the ps1 once... */
123  return(0);
124 }

◆ sceSdProcBatch()

int sceSdProcBatch ( sceSdBatch batch,
u32  returns[],
u32  num 
)

Definition at line 126 of file ps2snd.c.

127 {
128  /* TODO */
129  return(-1);
130 }

◆ sceSdProcBatchEx()

int sceSdProcBatchEx ( sceSdBatch batch,
u32  returns[],
u32  num,
u32  voice 
)

Definition at line 132 of file ps2snd.c.

133 {
134  /* TODO */
135  return(-1);
136 }

◆ sceSdSetAddr()

void sceSdSetAddr ( u16  entry,
u32  value 
)

Definition at line 82 of file ps2snd.c.

83 {
84  u32 buf[2] ALIGNED(64);
85  buf[0] = entry;
86  buf[1] = value;
87  SifCallRpc(&sd_client, PS2SND_SetAddr, 0, buf, 8, NULL, 0, NULL, NULL);
88 }
#define PS2SND_SetAddr
Definition: ps2snd.h:33

References ALIGNED, NULL, PS2SND_SetAddr, sd_client, and SifCallRpc().

◆ sceSdSetCoreAttr()

void sceSdSetCoreAttr ( u16  entry,
u16  value 
)

Definition at line 98 of file ps2snd.c.

99 {
100  u32 buf[2] ALIGNED(64);
101  buf[0] = entry;
102  buf[1] = value;
103  SifCallRpc(&sd_client, PS2SND_SetCoreAttr, 0, buf, 8, NULL, 0, NULL, NULL);
104 }
#define PS2SND_SetCoreAttr
Definition: ps2snd.h:35

References ALIGNED, NULL, PS2SND_SetCoreAttr, sd_client, and SifCallRpc().

◆ sceSdSetEffectAttr()

int sceSdSetEffectAttr ( int  core,
sceSdEffectAttr attr 
)

Definition at line 180 of file ps2snd.c.

181 {
182  s32 buf[1+((sizeof(sceSdEffectAttr)+3)/4)] ALIGNED(64);
183  buf[0] = core;
184  memcpy(&buf[1], attr, sizeof(sceSdEffectAttr));
185  SifCallRpc(&sd_client, PS2SND_SetEffectAttr, 0, buf, 4+sizeof(sceSdEffectAttr), buf, 4, NULL, NULL);
186  return(buf[0]);
187 }
#define PS2SND_SetEffectAttr
Definition: ps2snd.h:47

References ALIGNED, NULL, PS2SND_SetEffectAttr, sd_client, and SifCallRpc().

◆ sceSdSetParam()

void sceSdSetParam ( u16  entry,
u16  value 
)

Definition at line 50 of file ps2snd.c.

51 {
52  u32 buf[2] ALIGNED(64);
53  buf[0] = entry;
54  buf[1] = value;
55  SifCallRpc(&sd_client, PS2SND_SetParam, 0, buf, 8, NULL, 0, NULL, NULL);
56 }
#define PS2SND_SetParam
Definition: ps2snd.h:29

References ALIGNED, NULL, PS2SND_SetParam, sd_client, and SifCallRpc().

Referenced by main().

◆ sceSdSetSwitch()

void sceSdSetSwitch ( u16  entry,
u32  value 
)

Definition at line 66 of file ps2snd.c.

67 {
68  u32 buf[2] ALIGNED(64);
69  buf[0] = entry;
70  buf[1] = value;
71  SifCallRpc(&sd_client, PS2SND_SetSwitch, 0, buf, 8, NULL, 0, NULL, NULL);
72 }
#define PS2SND_SetSwitch
Definition: ps2snd.h:31

References ALIGNED, NULL, PS2SND_SetSwitch, sd_client, and SifCallRpc().

◆ sceSdVoiceTrans()

int sceSdVoiceTrans ( s16  channel,
u16  mode,
u8 m_addr,
u32 s_addr,
u32  size 
)

Definition at line 139 of file ps2snd.c.

140 {
141  u32 buf[5] ALIGNED(64);
142  ((s32 *)buf)[0] = channel;
143  buf[1] = mode;
144  buf[2] = (u32)m_addr;
145  buf[3] = (u32)s_addr;
146  buf[4] = size;
147 
148  SifCallRpc(&sd_client, PS2SND_VoiceTrans, 0, buf, 20, buf, 4, NULL, NULL);
149  return(((s32 *)buf)[0]);
150 }
#define PS2SND_VoiceTrans
Definition: ps2snd.h:41
s32 mode
Definition: rpc_client.c:15

References ALIGNED, mode, NULL, PS2SND_VoiceTrans, sd_client, and SifCallRpc().

Referenced by sndLoadSample().

◆ sceSdVoiceTransStatus()

u32 sceSdVoiceTransStatus ( s16  channel,
s16  flag 
)

Definition at line 157 of file ps2snd.c.

158 {
159  s32 buf[2] ALIGNED(64);
160  buf[0] = channel;
161  buf[1] = flag;
162 
163  SifCallRpc(&sd_client, PS2SND_VoiceTransStatus, 0, buf, 8, buf, 4, NULL, NULL);
164  return(((u32 *)buf)[0]);
165 }
#define PS2SND_VoiceTransStatus
Definition: ps2snd.h:43

References ALIGNED, NULL, PS2SND_VoiceTransStatus, sd_client, and SifCallRpc().

Referenced by sndLoadSample().

◆ sndLoadSample()

int sndLoadSample ( void *  buf,
u32  spuaddr,
int  size 
)

Definition at line 276 of file ps2snd.c.

277 {
278  void *iopbuf;
279  int id, iopfree;
280  SifDmaTransfer_t sifdma;
281 
282  iopfree = sndQueryMaxFreeMemSize()/2;
283  if (size>iopfree)
284  {
285  return(-1);
286  }
287 
288  iopbuf = SifAllocIopHeap(size);
289  if (iopbuf==0)
290  return(-1);
291 
292  FlushCache(0);
293 
294  sifdma.src = buf;
295  sifdma.dest = iopbuf;
296  sifdma.size = size;
297  sifdma.attr = 0;
298 
299  id = SifSetDma(&sifdma, 1);
300  while(SifDmaStat(id) >= 0);;
301  FlushCache(0);
302 
303  sceSdVoiceTrans(0, SD_TRANS_WRITE, iopbuf, (void*)spuaddr, size);
304  sceSdVoiceTransStatus(0, 1);
305 
306  SifFreeIopHeap(iopbuf);
307 
308  return(size);
309 }
void * SifAllocIopHeap(int size)
int SifFreeIopHeap(void *addr)
u32 SifSetDma(SifDmaTransfer_t *sdd, s32 len)
void FlushCache(s32 operation)
s32 SifDmaStat(u32 id)
#define SD_TRANS_WRITE
Definition: libsd-common.h:47
u32 sndQueryMaxFreeMemSize(void)
Definition: ps2snd.c:208
int sceSdVoiceTrans(s16 channel, u16 mode, u8 *m_addr, u32 *s_addr, u32 size)
Definition: ps2snd.c:139
u32 sceSdVoiceTransStatus(s16 channel, s16 flag)
Definition: ps2snd.c:157
void * dest
Definition: sifdma.h:55
void * src
Definition: sifdma.h:54

References SifDmaTransfer_t::attr, SifDmaTransfer_t::dest, FlushCache(), sceSdVoiceTrans(), sceSdVoiceTransStatus(), SD_TRANS_WRITE, SifAllocIopHeap(), SifDmaStat(), SifFreeIopHeap(), SifSetDma(), SifDmaTransfer_t::size, sndQueryMaxFreeMemSize(), and SifDmaTransfer_t::src.

◆ sndQueryMaxFreeMemSize()

u32 sndQueryMaxFreeMemSize ( void  )

Definition at line 208 of file ps2snd.c.

209 {
210  u32 buf[1] ALIGNED(64);
212  return(buf[0]);
213 }
#define PS2SND_QueryMaxFreeMemSize
Definition: ps2snd.h:62

References ALIGNED, NULL, PS2SND_QueryMaxFreeMemSize, sd_client, and SifCallRpc().

Referenced by sndLoadSample().

◆ sndStreamClose()

int sndStreamClose ( void  )

Definition at line 230 of file ps2snd.c.

231 {
232  s32 buf[1] ALIGNED(64);
233  SifCallRpc(&sd_client, PS2SND_StreamClose, 0, NULL, 0, buf, 4, NULL, NULL);
234  return(buf[0]);
235 }
#define PS2SND_StreamClose
Definition: ps2snd.h:54

References ALIGNED, NULL, PS2SND_StreamClose, sd_client, and SifCallRpc().

◆ sndStreamGetPosition()

int sndStreamGetPosition ( void  )

Definition at line 269 of file ps2snd.c.

270 {
271  s32 buf[1] ALIGNED(64);
273  return(buf[0]);
274 }
#define PS2SND_StreamGetPosition
Definition: ps2snd.h:58

References ALIGNED, NULL, PS2SND_StreamGetPosition, sd_client, and SifCallRpc().

◆ sndStreamOpen()

int sndStreamOpen ( char *  file,
u32  voices,
u32  flags,
u32  bufaddr,
u32  bufsize 
)

Definition at line 215 of file ps2snd.c.

216 {
217  u32 buf[32] ALIGNED(64);
218  buf[0] = voices;
219  buf[1] = flags;
220  buf[2] = bufaddr;
221  buf[3] = bufsize;
222  strncpy((char*)&buf[4], file, 27*4);
223  buf[31] = 0;
224 
225  SifCallRpc(&sd_client, PS2SND_StreamOpen, 0, buf, 128, buf, 4, NULL, NULL);
226  return(((s32 *)buf)[0]);
227 }
#define PS2SND_StreamOpen
Definition: ps2snd.h:53

References ALIGNED, NULL, PS2SND_StreamOpen, sd_client, and SifCallRpc().

Referenced by main().

◆ sndStreamPause()

int sndStreamPause ( void  )

Definition at line 245 of file ps2snd.c.

246 {
247  s32 buf[1] ALIGNED(64);
248  SifCallRpc(&sd_client, PS2SND_StreamPause, 0, NULL, 0, buf, 4, NULL, NULL);
249  return(buf[0]);
250 }
#define PS2SND_StreamPause
Definition: ps2snd.h:56

References ALIGNED, NULL, PS2SND_StreamPause, sd_client, and SifCallRpc().

◆ sndStreamPlay()

int sndStreamPlay ( void  )

Definition at line 237 of file ps2snd.c.

238 {
239  s32 buf[1] ALIGNED(64);
240  SifCallRpc(&sd_client, PS2SND_StreamPlay, 0, NULL, 0, buf, 4, NULL, NULL);
241  return(buf[0]);
242 }
#define PS2SND_StreamPlay
Definition: ps2snd.h:55

References ALIGNED, NULL, PS2SND_StreamPlay, sd_client, and SifCallRpc().

Referenced by main().

◆ sndStreamSetPosition()

int sndStreamSetPosition ( int  block)

Definition at line 252 of file ps2snd.c.

253 {
254  s32 buf[1] ALIGNED(64);
255  buf[0] = block;
256  SifCallRpc(&sd_client, PS2SND_StreamSetPosition, 0, buf, 4, buf, 4, NULL, NULL);
257  return(buf[0]);
258 }
#define PS2SND_StreamSetPosition
Definition: ps2snd.h:57

References ALIGNED, NULL, PS2SND_StreamSetPosition, sd_client, and SifCallRpc().

◆ sndStreamSetVolume()

int sndStreamSetVolume ( int  left,
int  right 
)

Definition at line 260 of file ps2snd.c.

261 {
262  s32 buf[2] ALIGNED(64);
263  buf[0] = left;
264  buf[1] = right;
265  SifCallRpc(&sd_client, PS2SND_StreamSetVolume, 0, buf, 8, buf, 4, NULL, NULL);
266  return(buf[0]);
267 }
#define PS2SND_StreamSetVolume
Definition: ps2snd.h:59

References ALIGNED, NULL, PS2SND_StreamSetVolume, sd_client, and SifCallRpc().

Variable Documentation

◆ sd_client

◆ sd_started

int sd_started = 0
static

Definition at line 19 of file ps2snd.c.

Referenced by sceSdInit().