ps2sdk
1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
|
#include <stdio.h>
#include <kernel.h>
#include <sifrpc.h>
#include <tamtypes.h>
#include <string.h>
#include <iopheap.h>
#include <audsrv.h>
#include "audsrv_rpc.h"
Go to the source code of this file.
Macros | |
#define | MIN(a, b) ((a) <= (b)) ? (a) : (b) |
Variables | |
static struct t_SifRpcClientData | cd0 |
static unsigned int | sbuff [4096] |
static struct t_SifRpcDataQueue | cb_queue |
static struct t_SifRpcServerData | cb_srv |
static unsigned char | rpc_server_stack [0x1800] |
void * | _gp |
static int | initialized = 0 |
static int | rpc_server_thread_id |
static int | audsrv_error = AUDSRV_ERR_NOERROR |
static int | completion_sema |
static audsrv_callback_t | on_cdda_stop = NULL |
static void * | on_cdda_stop_arg = NULL |
static audsrv_callback_t | on_fillbuf = NULL |
static void * | on_fillbuf_arg = NULL |
static const unsigned short | vol_values [26] |
audsrv EE-side RPC code.
Definition in file audsrv_rpc.c.
#define MIN | ( | a, | |
b | |||
) | ((a) <= (b)) ? (a) : (b) |
Definition at line 26 of file audsrv_rpc.c.
int audsrv_adpcm_init | ( | ) |
Initializes adpcm unit of audsrv
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.
References AUDSRV_INIT_ADPCM, and call_rpc_1().
Referenced by main().
int audsrv_adpcm_set_volume | ( | int | ch, |
int | vol | ||
) |
Sets output volume for the specified voice channel.
ch | Voice channel ID |
vol | volume in percentage (0-100) |
Definition at line 367 of file audsrv_rpc.c.
References AUDSRV_ADPCM_SET_VOLUME, call_rpc_2(), MAX_VOLUME, MIN_VOLUME, and vol_values.
Referenced by main().
int audsrv_ch_play_adpcm | ( | int | ch, |
audsrv_adpcm_t * | adpcm | ||
) |
Plays an adpcm sample already uploaded with audsrv_load_adpcm()
ch | channel identifier. Specifies one of the 24 voice channel to play the ADPCM channel on. |
id | sample identifier, as specified in load() |
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.
References AUDSRV_PLAY_ADPCM, and call_rpc_2().
Referenced by main().
|
static |
Definition at line 271 of file audsrv_rpc.c.
References AUDSRV_CDDA_CALLBACK, AUDSRV_FILLBUF_CALLBACK, buffer, NULL, on_cdda_stop, on_cdda_stop_arg, on_fillbuf, and on_fillbuf_arg.
Referenced by rpc_server_thread().
int audsrv_get_cd_status | ( | ) |
Returns the status of the CD tray (open, closed, seeking etc.)
Definition at line 223 of file audsrv_rpc.c.
References AUDSRV_GET_CD_STATUS, and call_rpc_1().
int audsrv_get_cd_type | ( | ) |
Returns the type of disc currently in tray
Definition at line 218 of file audsrv_rpc.c.
References AUDSRV_GET_CD_TYPE, and call_rpc_1().
int audsrv_get_cdpos | ( | ) |
Returns the current playing sector
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.
References AUDSRV_GET_CDPOS, and call_rpc_1().
Referenced by main().
int audsrv_get_error | ( | ) |
Returns the last error audsrv raised
Definition at line 66 of file audsrv_rpc.c.
References audsrv_error.
Referenced by audsrv_get_error_string().
const char* audsrv_get_error_string | ( | ) |
Translates audsrv_get_error() response to readable string
Definition at line 438 of file audsrv_rpc.c.
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().
int audsrv_get_numtracks | ( | ) |
Returns the number of tracks available on the CD in tray
Definition at line 198 of file audsrv_rpc.c.
References AUDSRV_GET_NUMTRACKS, and call_rpc_1().
Referenced by main().
int audsrv_get_track_offset | ( | int | track | ) |
Returns the first sector for the given track
track | track index, must be between 1 and the trackcount |
Definition at line 203 of file audsrv_rpc.c.
References AUDSRV_GET_TRACKOFFSET, and call_rpc_1().
Referenced by main().
int audsrv_get_trackpos | ( | ) |
Returns the current playing sector, relative to track
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.
References AUDSRV_GET_TRACKPOS, and call_rpc_1().
Referenced by main().
int audsrv_init | ( | ) |
Initializes audsrv library
Definition at line 296 of file audsrv_rpc.c.
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().
int audsrv_load_adpcm | ( | audsrv_adpcm_t * | adpcm, |
void * | buffer, | ||
int | size | ||
) |
Uploads a sample to SPU2 memory
adpcm | adpcm descriptor structure |
buffer | pointer to adpcm sample |
size | size of sample (including the header) |
Definition at line 381 of file audsrv_rpc.c.
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().
int audsrv_on_cdda_stop | ( | audsrv_callback_t | cb, |
void * | arg | ||
) |
Installs a callback function upon completion of a cdda track
cb | your callback |
arg | extra parameter to pass to callback function later |
Definition at line 464 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR, on_cdda_stop, and on_cdda_stop_arg.
Referenced by main().
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.
bytes | request a callback when this amount of bytes is available |
cb | your callback |
arg | extra parameter to pass to callback function later |
Definition at line 471 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR, AUDSRV_SET_THRESHOLD, call_rpc_1(), on_fillbuf, and on_fillbuf_arg.
Referenced by main().
int audsrv_pause_cd | ( | ) |
Pauses CDDA playing
If CDDA is paused, no operation is taken
Definition at line 208 of file audsrv_rpc.c.
References AUDSRV_PAUSE_CD, and call_rpc_1().
int audsrv_play_audio | ( | const char * | chunk, |
int | bytes | ||
) |
Uploads audio buffer to SPU
chunk | audio buffer |
bytes | size of chunk in bytes |
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.
References AUDSRV_ERR_NOERROR, AUDSRV_PLAY_AUDIO, cd0, completion_sema, MIN, NULL, sbuff, set_error(), SifCallRpc(), SignalSema(), and WaitSema().
Referenced by main().
int audsrv_play_cd | ( | int | track | ) |
Starts playing the request track
track | segment to play |
Definition at line 171 of file audsrv_rpc.c.
References AUDSRV_PLAY_CD, and call_rpc_1().
Referenced by main().
int audsrv_play_sectors | ( | int | start, |
int | end | ||
) |
Starts playing at a specific sector
start | first sector to play |
end | last sector to play |
Definition at line 176 of file audsrv_rpc.c.
References AUDSRV_PLAY_SECTORS, and call_rpc_2().
int audsrv_quit | ( | ) |
Shutdowns audsrv
Definition at line 117 of file audsrv_rpc.c.
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().
int audsrv_resume_cd | ( | ) |
Resumes CDDA playing
If CDDA was not paused, no operation is taken
Definition at line 213 of file audsrv_rpc.c.
References AUDSRV_RESUME_CD, and call_rpc_1().
int audsrv_set_format | ( | struct audsrv_fmt_t * | fmt | ) |
Configures audio stream
fmt | output specification structure |
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.
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().
int audsrv_set_volume | ( | int | volume | ) |
Sets output volume
vol | volume in percentage |
Definition at line 157 of file audsrv_rpc.c.
References AUDSRV_SET_VOLUME, call_rpc_1(), MAX_VOLUME, MIN_VOLUME, and vol_values.
Referenced by main().
int audsrv_stop_audio | ( | ) |
Stops audio from playing.
Definition at line 264 of file audsrv_rpc.c.
References AUDSRV_STOP_AUDIO, and call_rpc_1().
int audsrv_stop_cd | ( | ) |
Stops CD from playing.
Definition at line 181 of file audsrv_rpc.c.
References AUDSRV_STOP_CD, and call_rpc_1().
int audsrv_wait_audio | ( | int | bytes | ) |
Blocks until there is enough space to enqueue chunk
bytes | size of chunk requested to be enqueued (in bytes) |
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.
References AUDSRV_WAIT_AUDIO, and call_rpc_1().
Referenced by main().
|
static |
Internal function to simplify RPC calling
func | procedure to invoke |
arg | optional argument |
Definition at line 76 of file audsrv_rpc.c.
References cd0, completion_sema, NULL, sbuff, set_error(), SifCallRpc(), SignalSema(), and WaitSema().
Referenced by audsrv_adpcm_init(), audsrv_get_cd_status(), audsrv_get_cd_type(), audsrv_get_cdpos(), audsrv_get_numtracks(), audsrv_get_track_offset(), audsrv_get_trackpos(), audsrv_on_fillbuf(), audsrv_pause_cd(), audsrv_play_cd(), audsrv_resume_cd(), audsrv_set_volume(), audsrv_stop_audio(), audsrv_stop_cd(), and audsrv_wait_audio().
|
static |
Internal function to simplify RPC calling
func | procedure to invoke |
arg1 | optional argument |
arg2 | optional argument |
Definition at line 99 of file audsrv_rpc.c.
References cd0, completion_sema, NULL, sbuff, set_error(), SifCallRpc(), SignalSema(), and WaitSema().
Referenced by audsrv_adpcm_set_volume(), audsrv_ch_play_adpcm(), and audsrv_play_sectors().
|
static |
Definition at line 287 of file audsrv_rpc.c.
References audsrv_ee_rpc_handler(), AUDSRV_IRX, cb_queue, cb_srv, GetThreadId(), NULL, SifRegisterRpc(), SifRpcLoop(), and SifSetRpcQueue().
Referenced by audsrv_init().
|
static |
Internal function to set last error
err |
Definition at line 61 of file audsrv_rpc.c.
References audsrv_error.
Referenced by audsrv_init(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), call_rpc_1(), and call_rpc_2().
|
extern |
Referenced by audsrv_init().
|
static |
Definition at line 39 of file audsrv_rpc.c.
Referenced by audsrv_get_error(), and set_error().
|
static |
Definition at line 30 of file audsrv_rpc.c.
Referenced by audsrv_quit(), and rpc_server_thread().
|
static |
Definition at line 30 of file audsrv_rpc.c.
Referenced by audsrv_quit(), and rpc_server_thread().
|
static |
Definition at line 1 of file audsrv_rpc.c.
Referenced by audsrv_init(), audsrv_load_adpcm(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), call_rpc_1(), and call_rpc_2().
|
static |
Definition at line 40 of file audsrv_rpc.c.
Referenced by audsrv_init(), audsrv_load_adpcm(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), call_rpc_1(), and call_rpc_2().
|
static |
Definition at line 37 of file audsrv_rpc.c.
Referenced by audsrv_init().
|
static |
Definition at line 42 of file audsrv_rpc.c.
Referenced by audsrv_ee_rpc_handler(), and audsrv_on_cdda_stop().
|
static |
Definition at line 43 of file audsrv_rpc.c.
Referenced by audsrv_ee_rpc_handler(), and audsrv_on_cdda_stop().
|
static |
Definition at line 45 of file audsrv_rpc.c.
Referenced by audsrv_ee_rpc_handler(), and audsrv_on_fillbuf().
|
static |
Definition at line 46 of file audsrv_rpc.c.
Referenced by audsrv_ee_rpc_handler(), and audsrv_on_fillbuf().
|
static |
Definition at line 33 of file audsrv_rpc.c.
Referenced by audsrv_init().
|
static |
Definition at line 38 of file audsrv_rpc.c.
Referenced by audsrv_init(), and audsrv_quit().
|
static |
Definition at line 30 of file audsrv_rpc.c.
Referenced by audsrv_init(), audsrv_load_adpcm(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), call_rpc_1(), and call_rpc_2().
|
static |
Definition at line 48 of file audsrv_rpc.c.
Referenced by audsrv_adpcm_set_volume(), and audsrv_set_volume().