PS2SDK
PS2 Homebrew Libraries
|
#include <stdio.h>
#include <thbase.h>
#include <thsemap.h>
#include <loadcore.h>
#include <sysmem.h>
#include <intrman.h>
#include <sifcmd.h>
#include <libsd.h>
#include <sysclib.h>
#include <audsrv.h>
#include "audsrv_internal.h"
#include "common.h"
#include "rpc_server.h"
#include "rpc_client.h"
#include "upsamplers.h"
#include "hw.h"
#include "spu.h"
#include "debug_printf.h"
Go to the source code of this file.
Macros | |
#define | MODNAME "audsrv" |
#define | VERSION "0.93" |
Functions | |
IRX_ID (MODNAME, 1, 4) | |
static u8 core1_buf[0x1000] | __attribute__ ((aligned(16))) |
static void | play_thread (void *arg) |
static int | transfer_complete (void *arg) |
static void | update_volume () |
int | audsrv_stop_audio () |
int | audsrv_format_ok (int freq, int bits, int channels) |
int | audsrv_set_format (int freq, int bits, int channels) |
int | audsrv_init () |
int | audsrv_available () |
int | audsrv_queued () |
int | audsrv_wait_audio (int buflen) |
int | audsrv_play_audio (const char *buf, int buflen) |
int | audsrv_set_volume (int vol) |
int | audsrv_set_threshold (int amount) |
int | audsrv_quit () |
int | _start (int argc, char *argv[]) |
Variables | |
static int | core1_volume = MAX_VOLUME |
static int | core1_freq = 0 |
static int | core1_bits = 0 |
static int | core1_channels = 0 |
static int | core1_sample_shift = 0 |
static int | initialized = 0 |
static int | playing = 0 |
static char | ringbuf [20480] |
static int | ringbuf_size = sizeof(ringbuf) |
static int | readpos |
static int | writepos |
static int | play_tid = 0 |
static int | queue_sema = 0 |
static int | transfer_sema = 0 |
static int | fillbuf_threshold = 0 |
static int | format_changed = 0 |
static short | rendered_left [512] |
static short | rendered_right [512] |
struct irx_export_table | _exp_audsrv |
audsrv IOP server
Definition in file audsrv.c.
|
static |
double buffer for streaming
|
static |
Main playing thread
arg | not used |
This is the main playing thread. It feeds the SPU with upsampled, demux'd audio data, from what has been queued beforehand. The stream is constructed as a ring buffer. This thread only ends with TerminateThread, and is usually asleep, waiting for SPU to complete playing the current wave. SPU plays 2048 bytes blocks, which yields that this thread wakes and sleeps 93.75 times a second
Definition at line 429 of file audsrv.c.
References audsrv_available(), core1_bits, core1_channels, core1_freq, CpuResumeIntr(), CpuSuspendIntr(), fillbuf_threshold, find_upsampler(), format_changed, playing, queue_sema, readpos, ringbuf, ringbuf_size, and transfer_sema.
Referenced by audsrv_init().
|
static |
Transfer complete callback.
arg | not used |
Generated by SPU2, when a block was transmitted and now putting to upload a second block to the other buffer.
Definition at line 99 of file audsrv.c.
References transfer_sema.
Referenced by audsrv_init().
|
static |
Apply volume changes, or keep mute if not playing
Definition at line 108 of file audsrv.c.
References core1_volume, MAX_VOLUME, and playing.
Referenced by audsrv_play_audio(), audsrv_set_volume(), and audsrv_stop_audio().
int audsrv_stop_audio | ( | ) |
Stops all audio playing
Mutes output and stops accepting audio blocks; also, clears callbacks.
Definition at line 139 of file audsrv.c.
References AUDSRV_ERR_NOERROR, call_rpc_1(), fillbuf_threshold, playing, and update_volume().
Referenced by audsrv_init(), audsrv_quit(), and rpc_command().
int audsrv_format_ok | ( | int | freq, |
int | bits, | ||
int | channels | ||
) |
Checks if the format noted by frequency and depth is supported
freq | frequency in hz |
bits | bits per sample (8, 16) |
channels | channels |
Definition at line 156 of file audsrv.c.
References find_upsampler().
Referenced by audsrv_set_format(), and rpc_command().
int audsrv_set_format | ( | int | freq, |
int | bits, | ||
int | channels | ||
) |
Configures audio stream
freq | frequency in hz |
bits | bits per sample (8, 16) |
channels | number of channels |
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 178 of file audsrv.c.
References AUDSRV_ERR_NOERROR, audsrv_format_ok(), core1_bits, core1_channels, core1_freq, core1_sample_shift, format_changed, readpos, ringbuf_size, and writepos.
Referenced by audsrv_init().
int audsrv_init | ( | ) |
Initializes audsrv library
Definition at line 219 of file audsrv.c.
References AUDSRV_ERR_NOERROR, AUDSRV_INIT, audsrv_set_format(), audsrv_stop_audio(), create_thread(), initialized, play_thread(), play_tid, queue_sema, readpos, set_error(), transfer_complete(), transfer_sema, and writepos.
Referenced by rpc_command().
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 278 of file audsrv.c.
References call_rpc_1(), readpos, ringbuf_size, and writepos.
Referenced by audsrv_play_audio(), audsrv_wait_audio(), play_thread(), and rpc_command().
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 295 of file audsrv.c.
References call_rpc_1(), readpos, ringbuf_size, and writepos.
Referenced by rpc_command().
int audsrv_wait_audio | ( | int | buflen | ) |
Blocks until there is enough space to enqueue chunk
buflen | 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 314 of file audsrv.c.
References audsrv_available(), AUDSRV_ERR_NOERROR, call_rpc_1(), queue_sema, and ringbuf_size.
Referenced by rpc_command().
int audsrv_play_audio | ( | const char * | buf, |
int | buflen | ||
) |
Uploads audio buffer to SPU
buf | audio chunk |
buflen | 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 344 of file audsrv.c.
References audsrv_available(), AUDSRV_ERR_NOERROR, initialized, playing, readpos, ringbuf, ringbuf_size, set_error(), update_volume(), and writepos.
Referenced by rpc_command().
int audsrv_set_volume | ( | int | vol | ) |
Sets output volume
vol | volume in SPU2 units [0 .. 0x3fff] |
Definition at line 393 of file audsrv.c.
References AUDSRV_ERR_NOERROR, call_rpc_1(), core1_volume, MAX_VOLUME, MIN_VOLUME, and update_volume().
Referenced by rpc_command().
int audsrv_quit | ( | ) |
Shutdowns audsrv
Definition at line 512 of file audsrv.c.
References audsrv_adpcm_init(), AUDSRV_ERR_NOERROR, audsrv_stop_audio(), audsrv_stop_cd(), play_tid, queue_sema, set_error(), and transfer_sema.
Referenced by rpc_command().
int _start | ( | int | argc, |
char * | argv[] | ||
) |
IRX _start function
Initializes interrupts and the RPC thread. Oh, and greets the user.
Definition at line 556 of file audsrv.c.
References _exp_audsrv, audsrv_adpcm_init(), and CpuEnableIntr().
|
static |
core1 (sfx) volume
Definition at line 41 of file audsrv.c.
Referenced by audsrv_set_volume(), and update_volume().
|
static |
frequency set by user
Definition at line 43 of file audsrv.c.
Referenced by audsrv_set_format(), and play_thread().
|
static |
bits per sample, set by user
Definition at line 45 of file audsrv.c.
Referenced by audsrv_set_format(), and play_thread().
|
static |
number of audio channels
Definition at line 47 of file audsrv.c.
Referenced by audsrv_set_format(), and play_thread().
|
static |
shift count from bytes to samples
Definition at line 49 of file audsrv.c.
Referenced by audsrv_set_format().
|
static |
initialization status
Definition at line 53 of file audsrv.c.
Referenced by audsrv_init(), and audsrv_play_audio().
|
static |
playing (not mute) status
Definition at line 55 of file audsrv.c.
Referenced by audsrv_play_audio(), audsrv_stop_audio(), play_thread(), and update_volume().
|
static |
ring buffer itself
Definition at line 60 of file audsrv.c.
Referenced by audsrv_play_audio(), and play_thread().
|
static |
size of ring buffer in bytes
Definition at line 62 of file audsrv.c.
Referenced by audsrv_available(), audsrv_play_audio(), audsrv_queued(), audsrv_set_format(), audsrv_wait_audio(), and play_thread().
|
static |
reading head pointer
Definition at line 64 of file audsrv.c.
Referenced by audsrv_available(), audsrv_init(), audsrv_play_audio(), audsrv_queued(), audsrv_set_format(), and play_thread().
|
static |
writing head pointer
Definition at line 66 of file audsrv.c.
Referenced by audsrv_available(), audsrv_init(), audsrv_play_audio(), audsrv_queued(), and audsrv_set_format().
|
static |
playing thread id
Definition at line 69 of file audsrv.c.
Referenced by audsrv_init(), and audsrv_quit().
|
static |
semaphore for wait_audio()
Definition at line 71 of file audsrv.c.
Referenced by audsrv_init(), audsrv_quit(), audsrv_wait_audio(), and play_thread().
|
static |
SPU2 transfer complete semaphore
Definition at line 73 of file audsrv.c.
Referenced by audsrv_init(), audsrv_quit(), play_thread(), and transfer_complete().
|
static |
threshold to initiate a callback
Definition at line 75 of file audsrv.c.
Referenced by audsrv_stop_audio(), and play_thread().
|
static |
boolean to notify when format has changed
Definition at line 78 of file audsrv.c.
Referenced by audsrv_set_format(), and play_thread().
|
extern |
exports table
Referenced by _start().