PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
audsrv.h File Reference

Go to the source code of this file.

Data Structures

struct  audsrv_fmt_t
 
struct  audsrv_adpcm_t
 

Macros

#define AUDSRV_IRX   0x870884e
 
#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_adpcm_set_volume(ch, vol)   audsrv_adpcm_set_volume_and_pan(ch, vol, 0)
 
#define audsrv_play_adpcm(adpcm)   audsrv_ch_play_adpcm(-1, adpcm)
 

Typedefs

typedef struct audsrv_fmt_t audsrv_fmt_t
 
typedef struct audsrv_adpcm_t audsrv_adpcm_t
 
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_and_pan (int ch, int vol, 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)
 
int audsrv_on_cdda_stop (audsrv_callback_t cb, void *arg)
 
int audsrv_available ()
 
int audsrv_queued ()
 

Detailed Description

audsrv EE-side RPC code

Definition in file audsrv.h.


Data Structure Documentation

◆ audsrv_fmt_t

struct audsrv_fmt_t

structure used to set new format

Definition at line 41 of file audsrv.h.

Data Fields
int freq

output frequency in hz

int bits

bits per sample (8, 16)

int channels

output channels (1, 2)

◆ audsrv_adpcm_t

struct audsrv_adpcm_t

adpcm sample definition

Definition at line 52 of file audsrv.h.

Data Fields
int pitch
int loop
int channels
void * buffer
int size

Macro Definition Documentation

◆ AUDSRV_IRX

#define AUDSRV_IRX   0x870884e

Definition at line 19 of file audsrv.h.

◆ MIN_VOLUME

#define MIN_VOLUME   0

minmum volume

Definition at line 22 of file audsrv.h.

◆ MAX_VOLUME

#define MAX_VOLUME   100

maximum volume

Definition at line 25 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_RPC_FAILED

#define AUDSRV_ERR_RPC_FAILED   0x0002

Definition at line 30 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_OUT_OF_MEMORY

#define AUDSRV_ERR_OUT_OF_MEMORY   0x0004

Definition at line 32 of file audsrv.h.

◆ AUDSRV_ERR_ARGS

#define AUDSRV_ERR_ARGS   0x0005

Definition at line 33 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_FAILED_TO_LOAD_ADPCM

#define AUDSRV_ERR_FAILED_TO_LOAD_ADPCM   0x0010

Definition at line 37 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_adpcm_set_volume

#define audsrv_adpcm_set_volume (   ch,
  vol 
)    audsrv_adpcm_set_volume_and_pan(ch, vol, 0)

Definition at line 228 of file audsrv.h.

◆ audsrv_play_adpcm

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

Definition at line 249 of file audsrv.h.

Typedef Documentation

◆ audsrv_fmt_t

typedef struct audsrv_fmt_t audsrv_fmt_t

structure used to set new format

◆ audsrv_adpcm_t

adpcm sample definition

◆ audsrv_callback_t

typedef int(* audsrv_callback_t) (void *arg)

Definition at line 65 of file audsrv.h.

Function Documentation

◆ audsrv_init()

int audsrv_init ( )

Initializes audsrv library

Returns
error code

Initializes audsrv library

Returns
0 on success

Definition at line 328 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR, AUDSRV_INIT, and set_error().

Referenced by rpc_command().

◆ audsrv_quit()

int audsrv_quit ( )

Shutdowns audsrv

Returns
AUDSRV_ERR_NOERROR

Definition at line 143 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR, and set_error().

Referenced by rpc_command().

◆ 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 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().

◆ audsrv_wait_audio()

int audsrv_wait_audio ( int  buflen)

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.

Blocks until there is enough space to enqueue chunk

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

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.

References call_rpc_1().

Referenced by rpc_command().

◆ audsrv_set_volume()

int audsrv_set_volume ( int  vol)

Sets output volume

Parameters
volvolume in percentage
Returns
error code

Sets output volume

Parameters
volvolume in SPU2 units [0 .. 0x3fff]
Returns
0 on success, negative otherwise

Definition at line 183 of file audsrv_rpc.c.

References call_rpc_1(), MAX_VOLUME, and MIN_VOLUME.

Referenced by rpc_command().

◆ audsrv_play_audio()

int audsrv_play_audio ( const char *  buf,
int  buflen 
)

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.)

Uploads audio buffer to SPU

Parameters
bufaudio chunk
buflensize 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 254 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR, and set_error().

Referenced by rpc_command().

◆ audsrv_stop_audio()

int audsrv_stop_audio ( )

Stops audio from playing.

Returns
status code

Stops all audio playing

Returns
0, always

Mutes output and stops accepting audio blocks; also, clears callbacks.

Definition at line 292 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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.

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 498 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR, and audsrv_get_error().

◆ audsrv_play_cd()

int audsrv_play_cd ( int  track)

Starts playing the request track

Parameters
tracksegment to play
Returns
status code

Plays CD audio track

Parameters
tracksegment to play [1 .. 99]
Returns
error status

Definition at line 197 of file audsrv_rpc.c.

References AUDSRV_PLAY_CD, and call_rpc_1().

Referenced by rpc_command().

◆ audsrv_stop_cd()

int audsrv_stop_cd ( )

Stops CD from playing.

Returns
status code

Stops CD play

Returns
0, always

Stops CD from being played; this has no effect on other music audsrv is currently playing

Definition at line 207 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by audsrv_quit(), and rpc_command().

◆ 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.

Returns the current sector being played

Returns
sector number, or negative value on error

Definition at line 214 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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.

Returns the current sector being played, relative to first sector in track

Returns
sector number, or negative value on error

Definition at line 219 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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 224 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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 229 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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 234 of file audsrv_rpc.c.

References call_rpc_1().

◆ 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 239 of file audsrv_rpc.c.

References call_rpc_1().

◆ 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 202 of file audsrv_rpc.c.

References call_rpc_2().

◆ 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

Returns CD drive status

Returns
status according to PS2 native values

Definition at line 249 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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

Returns the type of disc in drive

Returns
disc type (according to native PS2 values) or -AUDSRV_ERR_NO_DISC

Definition at line 244 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().

◆ 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 531 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR, and call_rpc_1().

◆ 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

Initializes adpcm unit of audsrv

Returns
zero on success, negative value on error

Definition at line 394 of file audsrv_rpc.c.

References AUDSRV_INIT_ADPCM, and call_rpc_1().

Referenced by _start(), audsrv_quit(), and rpc_command().

◆ audsrv_adpcm_set_volume_and_pan()

int audsrv_adpcm_set_volume_and_pan ( int  ch,
int  vol,
int  pan 
)

Sets output volume for the specified voice channel.

Parameters
chVoice channel ID
volvolume in percentage (0-100)
panleft/right offset [-100 .. 0 .. 100]
Returns
0 on success, negative otherwise

Definition at line 399 of file audsrv_rpc.c.

References call_rpc_3(), MAX_VOLUME, and MIN_VOLUME.

◆ 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 430 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR.

Referenced by rpc_command().

◆ 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
channel identifier 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 481 of file audsrv_rpc.c.

References call_rpc_2().

Referenced by rpc_command().

◆ audsrv_is_adpcm_playing()

int audsrv_is_adpcm_playing ( int  ch,
audsrv_adpcm_t adpcm 
)

Check if a sample is currently playing on the given channel

Returns
1 if playing, 0 if not

Definition at line 487 of file audsrv_rpc.c.

References call_rpc_2().

Referenced by rpc_command().

◆ audsrv_free_adpcm()

int audsrv_free_adpcm ( audsrv_adpcm_t adpcm)

Remove an adpcm sample uploaded with audsrv_load_adpcm() from the list of loaded sounds

Parameters
idsample 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().

◆ 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 524 of file audsrv_rpc.c.

References AUDSRV_ERR_NOERROR.

◆ audsrv_available()

int audsrv_available ( )

Returns the number of bytes that can be queued

Returns
number of bytes left in the ring buffer

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.

Returns the number of bytes that can be queued

Returns
byte count

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.

References call_rpc_1().

Referenced by rpc_command().

◆ audsrv_queued()

int audsrv_queued ( )

Returns the number of bytes already in queue

Returns
byte count

Returns the number of bytes that are already in the ring buffer.

Definition at line 554 of file audsrv_rpc.c.

References call_rpc_1().

Referenced by rpc_command().