ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
audsrv.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  audsrv_fmt_t
 
struct  audsrv_adpcm_t
 

Macros

#define AUDSRV_IRX   0x870884d
 
#define MIN_VOLUME   0
 
#define MAX_VOLUME   100
 
#define AUDSRV_ERR_NOERROR   0x0000
 
#define AUDSRV_ERR_NOT_INITIALIZED   0x0001
 
#define AUDSRV_ERR_RPC_FAILED   0x0002
 
#define AUDSRV_ERR_FORMAT_NOT_SUPPORTED   0x0003
 
#define AUDSRV_ERR_OUT_OF_MEMORY   0x0004
 
#define AUDSRV_ERR_ARGS   0x0005
 
#define AUDSRV_ERR_NO_DISC   0x0006
 
#define AUDSRV_ERR_NO_MORE_CHANNELS   0x0007
 
#define AUDSRV_ERR_FAILED_TO_LOAD_ADPCM   0x0010
 
#define AUDSRV_ERR_FAILED_TO_CREATE_SEMA   0x0011
 
#define audsrv_play_adpcm(adpcm)   audsrv_ch_play_adpcm(-1, adpcm)
 

Typedefs

typedef int(* audsrv_callback_t) (void *arg)
 

Functions

int audsrv_init ()
 
int audsrv_quit ()
 
int audsrv_set_format (struct audsrv_fmt_t *fmt)
 
int audsrv_wait_audio (int bytes)
 
int audsrv_set_volume (int volume)
 
int audsrv_play_audio (const char *chunk, int bytes)
 
int audsrv_stop_audio ()
 
int audsrv_get_error ()
 
const char * audsrv_get_error_string ()
 
int audsrv_play_cd (int track)
 
int audsrv_stop_cd ()
 
int audsrv_get_cdpos ()
 
int audsrv_get_trackpos ()
 
int audsrv_get_numtracks ()
 
int audsrv_get_track_offset (int track)
 
int audsrv_pause_cd ()
 
int audsrv_resume_cd ()
 
int audsrv_play_sectors (int start, int end)
 
int audsrv_get_cd_status ()
 
int audsrv_get_cd_type ()
 
int audsrv_on_fillbuf (int amount, audsrv_callback_t cb, void *arg)
 
int audsrv_adpcm_init ()
 
int audsrv_adpcm_set_volume (int ch, int vol)
 
int audsrv_load_adpcm (audsrv_adpcm_t *adpcm, void *buffer, int size)
 
int audsrv_ch_play_adpcm (int ch, audsrv_adpcm_t *adpcm)
 
int audsrv_on_cdda_stop (audsrv_callback_t cb, void *arg)
 

Detailed Description

audsrv EE-side RPC code

Definition in file audsrv.h.

Macro Definition Documentation

◆ AUDSRV_ERR_ARGS

#define AUDSRV_ERR_ARGS   0x0005

Definition at line 33 of file audsrv.h.

◆ AUDSRV_ERR_FAILED_TO_CREATE_SEMA

#define AUDSRV_ERR_FAILED_TO_CREATE_SEMA   0x0011

Definition at line 38 of file audsrv.h.

◆ AUDSRV_ERR_FAILED_TO_LOAD_ADPCM

#define AUDSRV_ERR_FAILED_TO_LOAD_ADPCM   0x0010

Definition at line 37 of file audsrv.h.

◆ AUDSRV_ERR_FORMAT_NOT_SUPPORTED

#define AUDSRV_ERR_FORMAT_NOT_SUPPORTED   0x0003

Definition at line 31 of file audsrv.h.

◆ AUDSRV_ERR_NO_DISC

#define AUDSRV_ERR_NO_DISC   0x0006

Definition at line 34 of file audsrv.h.

◆ AUDSRV_ERR_NO_MORE_CHANNELS

#define AUDSRV_ERR_NO_MORE_CHANNELS   0x0007

Definition at line 35 of file audsrv.h.

◆ AUDSRV_ERR_NOERROR

#define AUDSRV_ERR_NOERROR   0x0000

error codes

Definition at line 28 of file audsrv.h.

◆ AUDSRV_ERR_NOT_INITIALIZED

#define AUDSRV_ERR_NOT_INITIALIZED   0x0001

Definition at line 29 of file audsrv.h.

◆ AUDSRV_ERR_OUT_OF_MEMORY

#define AUDSRV_ERR_OUT_OF_MEMORY   0x0004

Definition at line 32 of file audsrv.h.

◆ AUDSRV_ERR_RPC_FAILED

#define AUDSRV_ERR_RPC_FAILED   0x0002

Definition at line 30 of file audsrv.h.

◆ AUDSRV_IRX

#define AUDSRV_IRX   0x870884d

Definition at line 19 of file audsrv.h.

◆ audsrv_play_adpcm

#define audsrv_play_adpcm (   adpcm)    audsrv_ch_play_adpcm(-1, adpcm)

Definition at line 247 of file audsrv.h.

◆ MAX_VOLUME

#define MAX_VOLUME   100

maximum volume

Definition at line 25 of file audsrv.h.

◆ MIN_VOLUME

#define MIN_VOLUME   0

minmum volume

Definition at line 22 of file audsrv.h.

Typedef Documentation

◆ audsrv_callback_t

typedef int(* audsrv_callback_t) (void *arg)

Definition at line 65 of file audsrv.h.

Function Documentation

◆ audsrv_adpcm_init()

int audsrv_adpcm_init ( )

Initializes adpcm unit of audsrv

Returns
zero on success, negative value on error

Frees up all memory taken by samples, and stops all voices from being played. This can be called multiple times

Definition at line 362 of file audsrv_rpc.c.

363 {
364  return call_rpc_1(AUDSRV_INIT_ADPCM, 0);
365 }
static int call_rpc_1(int func, int arg)
Definition: audsrv_rpc.c:76
#define AUDSRV_INIT_ADPCM
Definition: audsrv_rpc.h:50

References AUDSRV_INIT_ADPCM, and call_rpc_1().

Referenced by main().

◆ audsrv_adpcm_set_volume()

int audsrv_adpcm_set_volume ( int  ch,
int  vol 
)

Sets output volume for the specified voice channel.

Parameters
chVoice channel ID
volvolume in percentage (0-100)
Returns
0 on success, negative otherwise

Definition at line 367 of file audsrv_rpc.c.

368 {
369  if (volume > MAX_VOLUME)
370  {
371  volume = MAX_VOLUME;
372  }
373  else if (volume < MIN_VOLUME)
374  {
375  volume = MIN_VOLUME;
376  }
377 
378  return call_rpc_2(AUDSRV_ADPCM_SET_VOLUME, ch, vol_values[volume/4]);
379 }
#define MAX_VOLUME
Definition: audsrv.h:25
#define MIN_VOLUME
Definition: audsrv.h:22
static int call_rpc_2(int func, int arg1, int arg2)
Definition: audsrv_rpc.c:99
static const unsigned short vol_values[26]
Definition: audsrv_rpc.c:48
#define AUDSRV_ADPCM_SET_VOLUME
Definition: audsrv_rpc.h:53

References AUDSRV_ADPCM_SET_VOLUME, call_rpc_2(), MAX_VOLUME, MIN_VOLUME, and vol_values.

Referenced by main().

◆ audsrv_ch_play_adpcm()

int audsrv_ch_play_adpcm ( int  ch,
audsrv_adpcm_t adpcm 
)

Plays an adpcm sample already uploaded with audsrv_load_adpcm()

Parameters
chchannel identifier. Specifies one of the 24 voice channel to play the ADPCM channel on.
idsample identifier, as specified in load()
Returns
zero on success, negative value on error

When ch is set to an invalid channel ID, the sample will be played in an unoccupied channel. If all 24 channels are used, then -AUDSRV_ERR_NO_MORE_CHANNELS is returned. When ch is set to a valid channel ID, -AUDSRV_ERR_NO_MORE_CHANNELS is returned if the channel is currently in use. Trying to play a sample which is unavailable will result in -AUDSRV_ERR_ARGS

Definition at line 432 of file audsrv_rpc.c.

433 {
434  /* on iop side, the sample id is like the pointer on ee side */
435  return call_rpc_2(AUDSRV_PLAY_ADPCM, ch, (u32)adpcm);
436 }
#define AUDSRV_PLAY_ADPCM
Definition: audsrv_rpc.h:52
unsigned int u32
Definition: tamtypes.h:30

References AUDSRV_PLAY_ADPCM, and call_rpc_2().

Referenced by main().

◆ audsrv_get_cd_status()

int audsrv_get_cd_status ( )

Returns the status of the CD tray (open, closed, seeking etc.)

Returns
value as defined in libcdvd, negative on error

Definition at line 223 of file audsrv_rpc.c.

224 {
225  return call_rpc_1(AUDSRV_GET_CD_STATUS, 0);
226 }
#define AUDSRV_GET_CD_STATUS
Definition: audsrv_rpc.h:46

References AUDSRV_GET_CD_STATUS, and call_rpc_1().

◆ audsrv_get_cd_type()

int audsrv_get_cd_type ( )

Returns the type of disc currently in tray

Returns
value as defined in libcdvd, negative on error

Definition at line 218 of file audsrv_rpc.c.

219 {
220  return call_rpc_1(AUDSRV_GET_CD_TYPE, 0);
221 }
#define AUDSRV_GET_CD_TYPE
Definition: audsrv_rpc.h:47

References AUDSRV_GET_CD_TYPE, and call_rpc_1().

◆ audsrv_get_cdpos()

int audsrv_get_cdpos ( )

Returns the current playing sector

Returns
sector number

CDDA type discs have sector size of 2352 bytes. There are 75 such sectors per second.

Definition at line 188 of file audsrv_rpc.c.

189 {
190  return call_rpc_1(AUDSRV_GET_CDPOS, 0);
191 }
#define AUDSRV_GET_CDPOS
Definition: audsrv_rpc.h:39

References AUDSRV_GET_CDPOS, and call_rpc_1().

Referenced by main().

◆ audsrv_get_error()

int audsrv_get_error ( )

Returns the last error audsrv raised

Returns
error code

Definition at line 66 of file audsrv_rpc.c.

67 {
68  return audsrv_error;
69 }
static int audsrv_error
Definition: audsrv_rpc.c:39

References audsrv_error.

Referenced by audsrv_get_error_string().

◆ audsrv_get_error_string()

const char* audsrv_get_error_string ( )

Translates audsrv_get_error() response to readable string

Returns
string representation of error code

Definition at line 438 of file audsrv_rpc.c.

439 {
440  switch(audsrv_get_error())
441  {
442  case AUDSRV_ERR_NOERROR:
443  return "No error";
444 
446  return "Not initialized";
447 
449  return "Out of IOP memory";
450 
452  return "RPC operation failed";
453 
455  return "Format not supported";
456 
457  case AUDSRV_ERR_NO_DISC:
458  return "No disc in drive";
459  }
460 
461  return "Unknown error";
462 }
#define AUDSRV_ERR_FORMAT_NOT_SUPPORTED
Definition: audsrv.h:31
#define AUDSRV_ERR_OUT_OF_MEMORY
Definition: audsrv.h:32
#define AUDSRV_ERR_NOT_INITIALIZED
Definition: audsrv.h:29
#define AUDSRV_ERR_NOERROR
Definition: audsrv.h:28
#define AUDSRV_ERR_RPC_FAILED
Definition: audsrv.h:30
#define AUDSRV_ERR_NO_DISC
Definition: audsrv.h:34
int audsrv_get_error()
Definition: audsrv_rpc.c:66

References AUDSRV_ERR_FORMAT_NOT_SUPPORTED, AUDSRV_ERR_NO_DISC, AUDSRV_ERR_NOERROR, AUDSRV_ERR_NOT_INITIALIZED, AUDSRV_ERR_OUT_OF_MEMORY, AUDSRV_ERR_RPC_FAILED, and audsrv_get_error().

Referenced by main().

◆ audsrv_get_numtracks()

int audsrv_get_numtracks ( )

Returns the number of tracks available on the CD in tray

Returns
positive track count, or negative error status code

Definition at line 198 of file audsrv_rpc.c.

199 {
200  return call_rpc_1(AUDSRV_GET_NUMTRACKS, 0);
201 }
#define AUDSRV_GET_NUMTRACKS
Definition: audsrv_rpc.h:41

References AUDSRV_GET_NUMTRACKS, and call_rpc_1().

Referenced by main().

◆ audsrv_get_track_offset()

int audsrv_get_track_offset ( int  track)

Returns the first sector for the given track

Parameters
tracktrack index, must be between 1 and the trackcount
Returns
sector number, or negative status code

Definition at line 203 of file audsrv_rpc.c.

204 {
205  return call_rpc_1(AUDSRV_GET_TRACKOFFSET, track);
206 }
#define AUDSRV_GET_TRACKOFFSET
Definition: audsrv_rpc.h:42

References AUDSRV_GET_TRACKOFFSET, and call_rpc_1().

Referenced by main().

◆ audsrv_get_trackpos()

int audsrv_get_trackpos ( )

Returns the current playing sector, relative to track

Returns
sector number

There are 75 sectors a second. To translate this position to mm:ss:ff use the following: mm = sector / (75*60) ss = (sector / 75) % 60 ff = sector % 75

where ff is the frame number, 1/75th of a second.

Definition at line 193 of file audsrv_rpc.c.

194 {
195  return call_rpc_1(AUDSRV_GET_TRACKPOS, 0);
196 }
#define AUDSRV_GET_TRACKPOS
Definition: audsrv_rpc.h:40

References AUDSRV_GET_TRACKPOS, and call_rpc_1().

Referenced by main().

◆ audsrv_init()

int audsrv_init ( )

Initializes audsrv library

Returns
error code

Definition at line 296 of file audsrv_rpc.c.

297 {
299  ee_thread_t rpcThread;
300  int ret;
301 
302  if (initialized)
303  {
304  /* already done */
305  return 0;
306  }
307 
308  memset(&cd0, '\0', sizeof(cd0));
309 
310  while (1)
311  {
312  if (SifBindRpc(&cd0, AUDSRV_IRX, 0) < 0)
313  {
315  return -1;
316  }
317 
318  if (cd0.server != 0)
319  {
320  break;
321  }
322 
323  nopdelay();
324  }
325 
326  compSema.init_count = 1;
327  compSema.max_count = 1;
328  compSema.option = 0;
330  if (completion_sema < 0)
331  {
333  return -1;
334  }
335 
336  /* Create RPC server */
337  rpcThread.attr = 0;
338  rpcThread.option = 0;
339  rpcThread.func = &rpc_server_thread;
340  rpcThread.stack = rpc_server_stack;
341  rpcThread.stack_size = sizeof(rpc_server_stack);
342  rpcThread.gp_reg = &_gp;
343  rpcThread.initial_priority = 0x60;
344  rpc_server_thread_id = CreateThread(&rpcThread);
346 
347  SifCallRpc(&cd0, AUDSRV_INIT, 0, sbuff, 64, sbuff, 64, NULL, NULL);
348  ret = sbuff[0];
349  if (ret != 0)
350  {
351  set_error(ret);
352  return ret;
353  }
354 
355  /* initialize IOP heap (for adpcm samples) */
356  SifInitIopHeap();
357 
359  return AUDSRV_ERR_NOERROR;
360 }
#define AUDSRV_ERR_FAILED_TO_CREATE_SEMA
Definition: audsrv.h:38
#define AUDSRV_IRX
Definition: audsrv.h:19
static struct t_SifRpcClientData cd0
Definition: audsrv_rpc.c:29
static void rpc_server_thread(void *arg)
Definition: audsrv_rpc.c:287
static int completion_sema
Definition: audsrv_rpc.c:40
static unsigned char rpc_server_stack[0x1800]
Definition: audsrv_rpc.c:33
static int rpc_server_thread_id
Definition: audsrv_rpc.c:38
void * _gp
static unsigned int sbuff[4096]
Definition: audsrv_rpc.c:30
static int initialized
Definition: audsrv_rpc.c:37
static void set_error(int err)
Definition: audsrv_rpc.c:61
#define AUDSRV_INIT
Definition: audsrv_rpc.h:24
int SifInitIopHeap(void)
s32 CreateSema(ee_sema_t *sema)
static void nopdelay(void)
Definition: kernel.h:141
s32 CreateThread(ee_thread_t *thread)
s32 StartThread(s32 thread_id, void *args)
ee_sema_t compSema
Definition: ps2cam_rpc.c:30
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
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)
int init_count
Definition: kernel.h:218
int max_count
Definition: kernel.h:217
u32 option
Definition: kernel.h:221
void * gp_reg
Definition: kernel.h:230
u32 option
Definition: kernel.h:234
int stack_size
Definition: kernel.h:229
void * func
Definition: kernel.h:227
void * stack
Definition: kernel.h:228
u32 attr
Definition: kernel.h:233
int initial_priority
Definition: kernel.h:231
#define NULL
Definition: tamtypes.h:91

References _gp, ee_thread_t::attr, AUDSRV_ERR_FAILED_TO_CREATE_SEMA, AUDSRV_ERR_NOERROR, AUDSRV_ERR_RPC_FAILED, AUDSRV_INIT, AUDSRV_IRX, cd0, completion_sema, compSema, CreateSema(), CreateThread(), ee_thread_t::func, ee_thread_t::gp_reg, ee_sema_t::init_count, ee_thread_t::initial_priority, initialized, ee_sema_t::max_count, nopdelay(), NULL, ee_sema_t::option, ee_thread_t::option, rpc_server_stack, rpc_server_thread(), rpc_server_thread_id, sbuff, set_error(), SifBindRpc(), SifCallRpc(), SifInitIopHeap(), ee_thread_t::stack, ee_thread_t::stack_size, and StartThread().

Referenced by main().

◆ audsrv_load_adpcm()

int audsrv_load_adpcm ( audsrv_adpcm_t adpcm,
void *  buffer,
int  size 
)

Uploads a sample to SPU2 memory

Parameters
adpcmadpcm descriptor structure
bufferpointer to adpcm sample
sizesize of sample (including the header)
Returns
zero on success, negative error code otherwise

Definition at line 381 of file audsrv_rpc.c.

382 {
383  void* iop_addr;
384  SifDmaTransfer_t sifdma;
385  int id, ret;
386 
387  iop_addr = SifAllocIopHeap(size);
388  if (iop_addr == 0)
389  {
390  return -AUDSRV_ERR_OUT_OF_MEMORY;
391  }
392 
393  sifdma.src = buffer;
394  sifdma.dest = iop_addr;
395  sifdma.size = size;
396  sifdma.attr = 0;
397 
398  /* send by dma */
399  while((id = SifSetDma(&sifdma, 1)) == 0);
400  while(SifDmaStat(id) >= 0);
401 
403 
404  sbuff[0] = (int)iop_addr;
405  sbuff[1] = size;
406  sbuff[2] = (int)adpcm; /* use as id */
407 
408  SifCallRpc(&cd0, AUDSRV_LOAD_ADPCM, 0, sbuff, 12, sbuff, 16, NULL, NULL);
409 
410  if(sbuff[0] != 0)
411  {
412  adpcm->buffer = 0;
413  ret = sbuff[0];
414  }
415  else
416  {
417  adpcm->buffer = buffer;
418  adpcm->size = size;
419  adpcm->pitch = sbuff[1];
420  adpcm->loop = sbuff[2];
421  adpcm->channels = sbuff[3];
422  ret = AUDSRV_ERR_NOERROR;
423  }
424 
426 
427  SifFreeIopHeap(iop_addr);
428 
429  return ret;
430 }
#define AUDSRV_LOAD_ADPCM
Definition: audsrv_rpc.h:51
void * SifAllocIopHeap(int size)
int SifFreeIopHeap(void *addr)
s32 SignalSema(s32 sema_id)
u32 SifSetDma(SifDmaTransfer_t *sdd, s32 len)
s32 WaitSema(s32 sema_id)
s32 SifDmaStat(u32 id)
u8 buffer[128]
Definition: rpc_client.c:19
void * dest
Definition: sifdma.h:55
void * src
Definition: sifdma.h:54
void * buffer
Definition: audsrv.h:57
int channels
Definition: audsrv.h:56

References SifDmaTransfer_t::attr, AUDSRV_ERR_NOERROR, AUDSRV_ERR_OUT_OF_MEMORY, AUDSRV_LOAD_ADPCM, buffer, audsrv_adpcm_t::buffer, cd0, audsrv_adpcm_t::channels, completion_sema, SifDmaTransfer_t::dest, audsrv_adpcm_t::loop, NULL, audsrv_adpcm_t::pitch, sbuff, SifAllocIopHeap(), SifCallRpc(), SifDmaStat(), SifFreeIopHeap(), SifSetDma(), SignalSema(), SifDmaTransfer_t::size, audsrv_adpcm_t::size, SifDmaTransfer_t::src, and WaitSema().

Referenced by main().

◆ audsrv_on_cdda_stop()

int audsrv_on_cdda_stop ( audsrv_callback_t  cb,
void *  arg 
)

Installs a callback function upon completion of a cdda track

Parameters
cbyour callback
argextra parameter to pass to callback function later
Returns
status code

Definition at line 464 of file audsrv_rpc.c.

465 {
466  on_cdda_stop = cb;
467  on_cdda_stop_arg = arg;
468  return AUDSRV_ERR_NOERROR;
469 }
static void * on_cdda_stop_arg
Definition: audsrv_rpc.c:43
static audsrv_callback_t on_cdda_stop
Definition: audsrv_rpc.c:42

References AUDSRV_ERR_NOERROR, on_cdda_stop, and on_cdda_stop_arg.

Referenced by main().

◆ audsrv_on_fillbuf()

int audsrv_on_fillbuf ( int  amount,
audsrv_callback_t  cb,
void *  arg 
)

Installs a callback function to be called when ringbuffer has enough space to transmit the request number of bytes.

Parameters
bytesrequest a callback when this amount of bytes is available
cbyour callback
argextra parameter to pass to callback function later
Returns
AUDSRV_ERR_NOERROR, AUDSRV_ERR_ARGS if amount is greater than sizeof(ringbuf)

Definition at line 471 of file audsrv_rpc.c.

472 {
473  int err;
474 
475  on_fillbuf = 0;
476  on_fillbuf_arg = 0;
477 
478  err = call_rpc_1(AUDSRV_SET_THRESHOLD, amount);
479  if (err != 0)
480  {
481  return err;
482  }
483 
484  on_fillbuf = cb;
485  on_fillbuf_arg = arg;
486  return AUDSRV_ERR_NOERROR;
487 }
static void * on_fillbuf_arg
Definition: audsrv_rpc.c:46
static audsrv_callback_t on_fillbuf
Definition: audsrv_rpc.c:45
#define AUDSRV_SET_THRESHOLD
Definition: audsrv_rpc.h:34

References AUDSRV_ERR_NOERROR, AUDSRV_SET_THRESHOLD, call_rpc_1(), on_fillbuf, and on_fillbuf_arg.

Referenced by main().

◆ audsrv_pause_cd()

int audsrv_pause_cd ( )

Pauses CDDA playing

Returns
error status code

If CDDA is paused, no operation is taken

Definition at line 208 of file audsrv_rpc.c.

209 {
210  return call_rpc_1(AUDSRV_PAUSE_CD, 0);
211 }
#define AUDSRV_PAUSE_CD
Definition: audsrv_rpc.h:43

References AUDSRV_PAUSE_CD, and call_rpc_1().

◆ audsrv_play_audio()

int audsrv_play_audio ( const char *  chunk,
int  bytes 
)

Uploads audio buffer to SPU

Parameters
chunkaudio buffer
bytessize of chunk in bytes
Returns
positive number of bytes sent to processor or negative error status

Plays an audio buffer; It will not interrupt a playing buffer, rather queue it up and play it as soon as possible without interfering with fluent streaming. The buffer and buflen are given in host format (i.e, 11025hz 8bit stereo.)

Definition at line 228 of file audsrv_rpc.c.

229 {
230  int copy, maxcopy, copied;
231  int packet_size;
232  int sent = 0;
233 
235  maxcopy = sizeof(sbuff) - sizeof(int);
236  while (bytes > 0)
237  {
239 
240  copy = MIN(bytes, maxcopy);
241  sbuff[0] = copy;
242  memcpy(&sbuff[1], chunk, copy);
243  packet_size = copy + sizeof(int);
244  SifCallRpc(&cd0, AUDSRV_PLAY_AUDIO, 0, sbuff, packet_size, sbuff, 1*4, NULL, NULL);
245 
246  copied = sbuff[0];
248 
249  if (copied < 0)
250  {
251  /* there was an error */
252  set_error(-copied);
253  break;
254  }
255 
256  chunk = chunk + copy;
257  bytes = bytes - copy;
258  sent = sent + copied;
259  }
260 
261  return sent;
262 }
#define MIN(a, b)
Definition: audsrv_rpc.c:26
#define AUDSRV_PLAY_AUDIO
Definition: audsrv_rpc.h:30

References AUDSRV_ERR_NOERROR, AUDSRV_PLAY_AUDIO, cd0, completion_sema, MIN, NULL, sbuff, set_error(), SifCallRpc(), SignalSema(), and WaitSema().

Referenced by main().

◆ audsrv_play_cd()

int audsrv_play_cd ( int  track)

Starts playing the request track

Parameters
tracksegment to play
Returns
status code

Definition at line 171 of file audsrv_rpc.c.

172 {
173  return call_rpc_1(AUDSRV_PLAY_CD, track);
174 }
#define AUDSRV_PLAY_CD
Definition: audsrv_rpc.h:37

References AUDSRV_PLAY_CD, and call_rpc_1().

Referenced by main().

◆ audsrv_play_sectors()

int audsrv_play_sectors ( int  start,
int  end 
)

Starts playing at a specific sector

Parameters
startfirst sector to play
endlast sector to play
Returns
status code

Definition at line 176 of file audsrv_rpc.c.

177 {
178  return call_rpc_2(AUDSRV_PLAY_SECTORS, start, end);
179 }
#define AUDSRV_PLAY_SECTORS
Definition: audsrv_rpc.h:45

References AUDSRV_PLAY_SECTORS, and call_rpc_2().

◆ audsrv_quit()

int audsrv_quit ( )

Shutdowns audsrv

Returns
AUDSRV_ERR_NOERROR

Definition at line 117 of file audsrv_rpc.c.

118 {
120 
121  SifCallRpc(&cd0, AUDSRV_QUIT, 0, sbuff, 1*4, sbuff, 4, NULL, NULL);
123 
128 
130  return 0;
131 }
static struct t_SifRpcServerData cb_srv
Definition: audsrv_rpc.c:32
static struct t_SifRpcDataQueue cb_queue
Definition: audsrv_rpc.c:31
#define AUDSRV_QUIT
Definition: audsrv_rpc.h:25
s32 DeleteSema(s32 sema_id)
s32 TerminateThread(s32 thread_id)
s32 DeleteThread(s32 thread_id)
SifRpcServerData_t * SifRemoveRpc(SifRpcServerData_t *sd, SifRpcDataQueue_t *queue)
SifRpcDataQueue_t * SifRemoveRpcQueue(SifRpcDataQueue_t *qd)

References AUDSRV_ERR_NOERROR, AUDSRV_QUIT, cb_queue, cb_srv, cd0, completion_sema, DeleteSema(), DeleteThread(), NULL, rpc_server_thread_id, sbuff, set_error(), SifCallRpc(), SifRemoveRpc(), SifRemoveRpcQueue(), TerminateThread(), and WaitSema().

Referenced by main().

◆ audsrv_resume_cd()

int audsrv_resume_cd ( )

Resumes CDDA playing

Returns
error status code

If CDDA was not paused, no operation is taken

Definition at line 213 of file audsrv_rpc.c.

214 {
215  return call_rpc_1(AUDSRV_RESUME_CD, 0);
216 }
#define AUDSRV_RESUME_CD
Definition: audsrv_rpc.h:44

References AUDSRV_RESUME_CD, and call_rpc_1().

◆ audsrv_set_format()

int audsrv_set_format ( struct audsrv_fmt_t fmt)

Configures audio stream

Parameters
fmtoutput specification structure
Returns
0 on success, or one of the error codes otherwise

This sets up audsrv to accept stream in this format and convert it to SPU2's native format if required. Note: it is possible to change the format at any point. You might want to stop audio prior to that, to prevent mismatched audio output.

Definition at line 133 of file audsrv_rpc.c.

134 {
135  int ret;
136 
138 
139  sbuff[0] = fmt->freq;
140  sbuff[1] = fmt->bits;
141  sbuff[2] = fmt->channels;
142  SifCallRpc(&cd0, AUDSRV_SET_FORMAT, 0, sbuff, 3*4, sbuff, 4, NULL, NULL);
143 
144  ret = sbuff[0];
146 
147  set_error(ret);
148 
149  return ret;
150 }
#define AUDSRV_SET_FORMAT
Definition: audsrv_rpc.h:29
int bits
Definition: audsrv.h:46
int freq
Definition: audsrv.h:44
int channels
Definition: audsrv.h:48

References AUDSRV_SET_FORMAT, audsrv_fmt_t::bits, cd0, audsrv_fmt_t::channels, completion_sema, audsrv_fmt_t::freq, NULL, sbuff, set_error(), SifCallRpc(), SignalSema(), and WaitSema().

Referenced by main().

◆ audsrv_set_volume()

int audsrv_set_volume ( int  volume)

Sets output volume

Parameters
volvolume in percentage
Returns
error code

Definition at line 157 of file audsrv_rpc.c.

158 {
159  if (volume > MAX_VOLUME)
160  {
161  volume = MAX_VOLUME;
162  }
163  else if (volume < MIN_VOLUME)
164  {
165  volume = MIN_VOLUME;
166  }
167 
168  return call_rpc_1(AUDSRV_SET_VOLUME, vol_values[volume/4]);
169 }
#define AUDSRV_SET_VOLUME
Definition: audsrv_rpc.h:33

References AUDSRV_SET_VOLUME, call_rpc_1(), MAX_VOLUME, MIN_VOLUME, and vol_values.

Referenced by main().

◆ audsrv_stop_audio()

int audsrv_stop_audio ( )

Stops audio from playing.

Returns
status code

Definition at line 264 of file audsrv_rpc.c.

265 {
266  int ret;
267  ret = call_rpc_1(AUDSRV_STOP_AUDIO, 0);
268  return ret;
269 }
#define AUDSRV_STOP_AUDIO
Definition: audsrv_rpc.h:32

References AUDSRV_STOP_AUDIO, and call_rpc_1().

◆ audsrv_stop_cd()

int audsrv_stop_cd ( )

Stops CD from playing.

Returns
status code

Definition at line 181 of file audsrv_rpc.c.

182 {
183  int ret;
184  ret = call_rpc_1(AUDSRV_STOP_CD, 0);
185  return ret;
186 }
#define AUDSRV_STOP_CD
Definition: audsrv_rpc.h:38

References AUDSRV_STOP_CD, and call_rpc_1().

◆ audsrv_wait_audio()

int audsrv_wait_audio ( int  bytes)

Blocks until there is enough space to enqueue chunk

Parameters
bytessize of chunk requested to be enqueued (in bytes)
Returns
error code

Blocks until there are enough space to store the upcoming chunk in audsrv's internal ring buffer.

Definition at line 152 of file audsrv_rpc.c.

153 {
154  return call_rpc_1(AUDSRV_WAIT_AUDIO, bytes);
155 }
#define AUDSRV_WAIT_AUDIO
Definition: audsrv_rpc.h:31

References AUDSRV_WAIT_AUDIO, and call_rpc_1().

Referenced by main().