PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
adpcm.c File Reference
#include <stdio.h>
#include <thbase.h>
#include <thsemap.h>
#include <loadcore.h>
#include <sysmem.h>
#include <intrman.h>
#include <libsd.h>
#include <sysclib.h>
#include <audsrv.h>
#include "audsrv_internal.h"
#include "common.h"
#include "rpc_server.h"
#include "spu.h"
#include "debug_printf.h"
+ Include dependency graph for adpcm.c:

Go to the source code of this file.

Data Structures

struct  adpcm_list_t
 

Typedefs

typedef struct adpcm_list_t adpcm_list_t
 

Functions

static u32 sbuffer[16] __attribute__ ((aligned(16)))
 
static adpcm_list_talloc_new_sample (void)
 
static void free_all_samples ()
 
int free_sample (u32 id)
 
static adpcm_list_tadpcm_loaded (int id)
 
static void audsrv_read_adpcm_header (adpcm_list_t *adpcm, const u32 *buffer)
 
void * audsrv_load_adpcm (u32 *buffer, int size, int id)
 
int audsrv_is_adpcm_playing (int ch, u32 id)
 
static int audsrv_adpcm_alloc_channel (void)
 
int audsrv_ch_play_adpcm (int ch, u32 id)
 
int audsrv_adpcm_init ()
 
int audsrv_adpcm_set_volume (int ch, int voll, int volr)
 

Variables

static adpcm_list_tadpcm_list_head = 0
 
static adpcm_list_tadpcm_list_tail = 0
 

Detailed Description

audsrv adpcm module

Definition in file adpcm.c.


Data Structure Documentation

◆ adpcm_list_t

struct adpcm_list_t

Definition at line 31 of file adpcm.c.

+ Collaboration diagram for adpcm_list_t:
Data Fields
struct adpcm_list_t * next
int id
int pitch
int loop
int channels
int size
int spu2_addr

Function Documentation

◆ alloc_new_sample()

static adpcm_list_t * alloc_new_sample ( void  )
static

Allocates memory for a new sample.

Definition at line 49 of file adpcm.c.

References CpuResumeIntr(), and CpuSuspendIntr().

Referenced by audsrv_load_adpcm().

◆ free_all_samples()

static void free_all_samples ( )
static

Frees up all memory taken by the linked list of samples

Definition at line 62 of file adpcm.c.

References CpuResumeIntr(), and CpuSuspendIntr().

Referenced by audsrv_adpcm_init().

◆ free_sample()

int free_sample ( u32  id)

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 84 of file adpcm.c.

References AUDSRV_ERR_NOERROR, CpuResumeIntr(), and CpuSuspendIntr().

Referenced by rpc_command().

◆ adpcm_loaded()

static adpcm_list_t * adpcm_loaded ( int  id)
static

Looks up the given identifier in list of loaded samples

Parameters
idsample identifier
Returns
node entry from container, NULL on failure

Definition at line 126 of file adpcm.c.

Referenced by audsrv_ch_play_adpcm(), and audsrv_load_adpcm().

◆ audsrv_read_adpcm_header()

static void audsrv_read_adpcm_header ( adpcm_list_t adpcm,
const u32 *  buffer 
)
static

Extracts adpcm parameters from header

Parameters
adpcmnode entry
bufferpointer to adpcm header

Definition at line 147 of file adpcm.c.

Referenced by audsrv_load_adpcm().

◆ audsrv_load_adpcm()

void * audsrv_load_adpcm ( u32 *  buffer,
int  size,
int  id 
)

Uploads a sample to SPU2 memory

Parameters
bufferpointer to adpcm sample header
sizesize of sample in bytes
idsample identifier (to be later used in play())
Returns
pointer to local adpcm buffer

Definition at line 160 of file adpcm.c.

References adpcm_loaded(), alloc_new_sample(), and audsrv_read_adpcm_header().

◆ audsrv_is_adpcm_playing()

int audsrv_is_adpcm_playing ( int  ch,
u32  id 
)

Definition at line 211 of file adpcm.c.

◆ audsrv_adpcm_alloc_channel()

static int audsrv_adpcm_alloc_channel ( void  )
static

Definition at line 233 of file adpcm.c.

◆ audsrv_ch_play_adpcm()

int audsrv_ch_play_adpcm ( int  ch,
u32  id 
)

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. If set to an invalid channel ID, an unoccupied channel will be selected.
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 277 of file adpcm.c.

References adpcm_loaded().

◆ audsrv_adpcm_init()

int audsrv_adpcm_init ( )

Initializes adpcm unit of audsrv

Returns
zero on success, negative value on error

Definition at line 319 of file adpcm.c.

References AUDSRV_ERR_NOERROR, AUDSRV_INIT_ADPCM, call_rpc_1(), and free_all_samples().

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

◆ audsrv_adpcm_set_volume()

int audsrv_adpcm_set_volume ( int  ch,
int  voll,
int  volr 
)

Sets output volume for the specified voice channel.

Parameters
chVoice channel ID
vollleft volume in SPU2 units [0 .. 0x3fff]
volrright volume in SPU2 units [0 .. 0x3fff]
Returns
0 on success, negative otherwise

Definition at line 347 of file adpcm.c.

References AUDSRV_ERR_NOERROR, and MAX_VOLUME.

Variable Documentation

◆ adpcm_list_head

adpcm_list_t* adpcm_list_head = 0
static

Definition at line 43 of file adpcm.c.

◆ adpcm_list_tail

adpcm_list_t* adpcm_list_tail = 0
static

Definition at line 44 of file adpcm.c.