PS2SDK
PS2 Homebrew Libraries
|
#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) |
Functions | |
static unsigned int sbuff[4096] | __attribute__ ((aligned(64))) |
static unsigned char rpc_server_stack[0x1800] | __attribute__ ((aligned(16))) |
static void | set_error (int err) |
int | audsrv_get_error () |
static int | call_rpc_1 (int func, int arg) |
static int | call_rpc_2 (int func, int arg1, int arg2) |
static int | call_rpc_3 (int func, int arg1, int arg2, int arg3) |
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_cd (int track) |
int | audsrv_play_sectors (int start, int end) |
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_get_cd_type () |
int | audsrv_get_cd_status () |
int | audsrv_play_audio (const char *chunk, int bytes) |
int | audsrv_stop_audio () |
static void * | audsrv_ee_rpc_handler (int fnum, void *buffer, int len) |
static void | rpc_server_thread (void *arg) |
int | audsrv_init () |
int | audsrv_adpcm_init () |
int | audsrv_adpcm_set_volume_and_pan (int ch, int volume, int pan) |
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_is_adpcm_playing (int ch, audsrv_adpcm_t *adpcm) |
int | audsrv_free_adpcm (audsrv_adpcm_t *adpcm) |
const char * | audsrv_get_error_string () |
int | audsrv_on_cdda_stop (audsrv_callback_t cb, void *arg) |
int | audsrv_on_fillbuf (int amount, audsrv_callback_t cb, void *arg) |
int | audsrv_available () |
int | audsrv_queued () |
Variables | |
static struct t_SifRpcClientData | cd0 |
static struct t_SifRpcDataQueue | cb_queue |
static struct t_SifRpcServerData | cb_srv |
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.
|
static |
Internal function to set last error
err |
Definition at line 61 of file audsrv_rpc.c.
Referenced by audsrv_init(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), call_rpc_1(), call_rpc_2(), and call_rpc_3().
int audsrv_get_error | ( | ) |
Returns the last error audsrv raised
Definition at line 66 of file audsrv_rpc.c.
Referenced by audsrv_get_error_string().
|
static |
Internal function to simplify RPC calling
func | procedure to invoke |
arg | optional argument |
Definition at line 76 of file audsrv_rpc.c.
References set_error().
Referenced by audsrv_adpcm_init(), audsrv_available(), audsrv_free_adpcm(), 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_queued(), 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 set_error().
Referenced by audsrv_ch_play_adpcm(), audsrv_is_adpcm_playing(), and audsrv_play_sectors().
|
static |
Internal function to simplify RPC calling
func | procedure to invoke |
arg1 | optional argument |
arg2 | optional argument |
arg3 | optional argument |
Definition at line 124 of file audsrv_rpc.c.
References set_error().
Referenced by audsrv_adpcm_set_volume_and_pan().
int audsrv_quit | ( | ) |
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 159 of file audsrv_rpc.c.
References audsrv_fmt_t::bits, audsrv_fmt_t::channels, audsrv_fmt_t::freq, and set_error().
Referenced by rpc_command().
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 178 of file audsrv_rpc.c.
int audsrv_set_volume | ( | int | volume | ) |
Sets output volume
vol | volume in percentage |
Definition at line 183 of file audsrv_rpc.c.
int audsrv_play_cd | ( | int | track | ) |
Starts playing the request track
track | segment to play |
Definition at line 197 of file audsrv_rpc.c.
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 202 of file audsrv_rpc.c.
References call_rpc_2().
int audsrv_stop_cd | ( | ) |
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 214 of file audsrv_rpc.c.
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 219 of file audsrv_rpc.c.
int audsrv_get_numtracks | ( | ) |
Returns the number of tracks available on the CD in tray
Definition at line 224 of file audsrv_rpc.c.
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 229 of file audsrv_rpc.c.
int audsrv_pause_cd | ( | ) |
Pauses CDDA playing
If CDDA is paused, no operation is taken
Definition at line 234 of file audsrv_rpc.c.
References call_rpc_1().
int audsrv_resume_cd | ( | ) |
Resumes CDDA playing
If CDDA was not paused, no operation is taken
Definition at line 239 of file audsrv_rpc.c.
References call_rpc_1().
int audsrv_get_cd_type | ( | ) |
Returns the type of disc currently in tray
Definition at line 244 of file audsrv_rpc.c.
int audsrv_get_cd_status | ( | ) |
Returns the status of the CD tray (open, closed, seeking etc.)
Definition at line 249 of file audsrv_rpc.c.
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 254 of file audsrv_rpc.c.
int audsrv_stop_audio | ( | ) |
|
static |
Definition at line 299 of file audsrv_rpc.c.
|
static |
Definition at line 317 of file audsrv_rpc.c.
int audsrv_init | ( | ) |
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 394 of file audsrv_rpc.c.
int audsrv_adpcm_set_volume_and_pan | ( | int | ch, |
int | vol, | ||
int | pan | ||
) |
Sets output volume for the specified voice channel.
ch | Voice channel ID |
vol | volume in percentage (0-100) |
pan | left/right offset [-100 .. 0 .. 100] |
Definition at line 399 of file audsrv_rpc.c.
References call_rpc_3(), MAX_VOLUME, and MIN_VOLUME.
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 430 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR.
Referenced by rpc_command().
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 481 of file audsrv_rpc.c.
References call_rpc_2().
Referenced by rpc_command().
int audsrv_is_adpcm_playing | ( | int | ch, |
audsrv_adpcm_t * | adpcm | ||
) |
Check if a sample is currently playing on the given channel
Definition at line 487 of file audsrv_rpc.c.
References call_rpc_2().
Referenced by rpc_command().
int audsrv_free_adpcm | ( | audsrv_adpcm_t * | adpcm | ) |
Remove an adpcm sample uploaded with audsrv_load_adpcm() from the list of loaded sounds
id | sample identifier, as specified in load() |
SPU memory is freed only when there are no sounds in the list that where loaded after the ones that have been freed
Definition at line 492 of file audsrv_rpc.c.
References call_rpc_1().
const char * audsrv_get_error_string | ( | ) |
Translates audsrv_get_error() response to readable string
Definition at line 498 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR, and audsrv_get_error().
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 524 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR.
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 531 of file audsrv_rpc.c.
References AUDSRV_ERR_NOERROR, and call_rpc_1().
int audsrv_available | ( | ) |
Returns the number of bytes that can be queued
Returns the number of bytes that are available in the ring buffer. This is the total bytes that can be queued, without collision of the reading head with the writing head.
Definition at line 549 of file audsrv_rpc.c.
int audsrv_queued | ( | ) |
Returns the number of bytes already in queue
Returns the number of bytes that are already in the ring buffer.
Definition at line 554 of file audsrv_rpc.c.
|
static |
Definition at line 29 of file audsrv_rpc.c.
|
static |
Definition at line 31 of file audsrv_rpc.c.
|
static |
Definition at line 32 of file audsrv_rpc.c.
|
static |
Definition at line 37 of file audsrv_rpc.c.
|
static |
Definition at line 38 of file audsrv_rpc.c.
|
static |
Definition at line 39 of file audsrv_rpc.c.
|
static |
Definition at line 40 of file audsrv_rpc.c.
|
static |
Definition at line 42 of file audsrv_rpc.c.
|
static |
Definition at line 43 of file audsrv_rpc.c.
|
static |
Definition at line 45 of file audsrv_rpc.c.
|
static |
Definition at line 46 of file audsrv_rpc.c.
|
static |
Definition at line 48 of file audsrv_rpc.c.