PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
cdrom.c File Reference
#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 <cdvdman.h>
#include <sysclib.h>
#include <audsrv.h>
#include "cdrom.h"
#include "common.h"
#include "rpc_server.h"
#include "rpc_client.h"
#include "upsamplers.h"
#include "spu.h"
#include "hw.h"
#include "debug_printf.h"
+ Include dependency graph for cdrom.c:

Go to the source code of this file.

Functions

static u8 cd_ringbuf[SECTOR_SIZE *8] __attribute__ ((aligned(16)))
 
static int audsrv_cd_init ()
 
static int cd_transfer_complete (void *arg)
 
int audsrv_get_cd_type ()
 
int audsrv_get_cd_status ()
 
static int process_toc ()
 
static int initialize_cdda ()
 
int audsrv_get_numtracks ()
 
int audsrv_get_track_offset (int track)
 
static int read_sectors (void *dest, int sector, int count)
 
static void audsrv_stop_cd_stream ()
 
int audsrv_cd_pause ()
 
int audsrv_cd_resume ()
 
static void cdda_procedure (void *arg)
 
int audsrv_get_cdpos ()
 
int audsrv_get_trackpos ()
 
int audsrv_cd_play_sectors (int start, int end)
 
int audsrv_play_cd (int track)
 
int audsrv_stop_cd ()
 

Variables

static int cdda_initialized = 0
 
static int cd_playing = 0
 
static volatile int cd_paused = 0
 
static int cdda_play_tid = -1
 
static volatile int cdda_pos = 0
 
static int cdda_play_start = 0
 
static int cdda_play_end = 0
 
static cdda_toc toc
 
static unsigned char raw_toc [3000]
 
static int cd_transfer_sema = -1
 
static short cd_rendered_left [512]
 
static short cd_rendered_right [512]
 

Detailed Description

cdsrv IOP server.

Definition in file cdrom.c.

Function Documentation

◆ __attribute__()

static u8 cd_ringbuf[SECTOR_SIZE *8] __attribute__ ( (aligned(16))  )
static

cdda ring buffer

used upon overflow

◆ audsrv_cd_init()

static int audsrv_cd_init ( )
static

Definition at line 68 of file cdrom.c.

◆ cd_transfer_complete()

static int cd_transfer_complete ( void *  arg)
static

Transfer complete callback for cdda

Parameters
argnot used
Returns
true, always

Generated by SPU2, when a block was transmitted and now putting to upload a second block to the other buffer.

Definition at line 91 of file cdrom.c.

References cd_transfer_sema.

Referenced by cdda_procedure().

◆ audsrv_get_cd_type()

int audsrv_get_cd_type ( )

Returns the type of disc in drive

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

Definition at line 102 of file cdrom.c.

References call_rpc_1(), and sceCdGetDiskType().

Referenced by rpc_command().

◆ audsrv_get_cd_status()

int audsrv_get_cd_status ( )

Returns CD drive status

Returns
status according to PS2 native values

Definition at line 118 of file cdrom.c.

References call_rpc_1(), and sceCdStatus().

Referenced by rpc_command().

◆ process_toc()

static int process_toc ( )
static

Internal function to process raw toc loaded from disc

Returns
status code

Definition at line 126 of file cdrom.c.

References sceCdlLOCCD::minute, raw_toc, sceCdGetToc(), sceCdlLOCCD::second, sceCdlLOCCD::sector, toc, and sceCdlLOCCD::track.

◆ initialize_cdda()

static int initialize_cdda ( )
static

Definition at line 157 of file cdrom.c.

◆ 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 205 of file cdrom.c.

References call_rpc_1(), and toc.

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 220 of file cdrom.c.

References call_rpc_1(), sceCdlLOCCD::minute, sceCdlLOCCD::second, sceCdlLOCCD::sector, and toc.

Referenced by audsrv_play_cd(), and rpc_command().

◆ read_sectors()

static int read_sectors ( void *  dest,
int  sector,
int  count 
)
static

Reads several sectors from CDDA track

Parameters
destoutput buffer, must be atleast count*2352 bytes long
sectorfirst sector
countamount of sectors to read
Returns
total sectors read, negative on error

Definition at line 247 of file cdrom.c.

References count, sceCdDiskReady(), SCECdSpinNom, and sceCdSync().

Referenced by cdda_procedure().

◆ audsrv_stop_cd_stream()

static void audsrv_stop_cd_stream ( )
static

Stops cd SPU transmission

Definition at line 283 of file cdrom.c.

References cd_playing, cdda_play_end, cdda_play_start, and cdda_pos.

Referenced by audsrv_stop_cd().

◆ audsrv_cd_pause()

int audsrv_cd_pause ( )

Pauses CD playing

Returns
status code

Definition at line 298 of file cdrom.c.

References AUDSRV_ERR_NOERROR, and cd_paused.

Referenced by rpc_command().

◆ audsrv_cd_resume()

int audsrv_cd_resume ( )

Resumes CD playing

Returns
status code

Definition at line 307 of file cdrom.c.

References AUDSRV_ERR_NOERROR, and cd_paused.

Referenced by rpc_command().

◆ cdda_procedure()

static void cdda_procedure ( void *  arg)
static

Internal cdda feeding thread

Parameters
arg(not used)

Definition at line 316 of file cdrom.c.

References audsrv_stop_cd(), cd_paused, cd_transfer_complete(), cd_transfer_sema, cdda_play_end, cdda_play_start, cdda_pos, CpuResumeIntr(), CpuSuspendIntr(), find_upsampler(), and read_sectors().

Referenced by audsrv_cd_play_sectors().

◆ audsrv_get_cdpos()

int audsrv_get_cdpos ( )

Returns the current sector being played

Returns
sector number, or negative value on error

Definition at line 438 of file cdrom.c.

References call_rpc_1(), cd_playing, and cdda_pos.

Referenced by rpc_command().

◆ audsrv_get_trackpos()

int audsrv_get_trackpos ( )

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

Returns
sector number, or negative value on error

Definition at line 452 of file cdrom.c.

References call_rpc_1(), cd_playing, cdda_play_start, and cdda_pos.

Referenced by rpc_command().

◆ audsrv_cd_play_sectors()

int audsrv_cd_play_sectors ( int  start,
int  end 
)

Starts playing cdda sectors from disc

Parameters
startfirst sector to play
endstop playing at this sector
Returns
status code

Starts the cdda feeding thread at the given sector. Any previously set up playback is stopped. If a callback was set, it will NOT be called, as the thread is stopped abnormally.

Definition at line 472 of file cdrom.c.

References AUDSRV_ERR_NOERROR, audsrv_stop_cd(), cd_playing, cdda_play_end, cdda_play_start, cdda_play_tid, cdda_pos, cdda_procedure(), and create_thread().

Referenced by audsrv_play_cd(), and rpc_command().

◆ audsrv_play_cd()

int audsrv_play_cd ( int  track)

Plays CD audio track

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

Definition at line 508 of file cdrom.c.

References audsrv_cd_play_sectors(), audsrv_get_track_offset(), AUDSRV_PLAY_CD, call_rpc_1(), MAX_VOLUME, sceCdGetDiskType(), and toc.

Referenced by rpc_command().

◆ audsrv_stop_cd()

int audsrv_stop_cd ( )

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 564 of file cdrom.c.

References audsrv_stop_cd_stream(), call_rpc_1(), and cdda_play_tid.

Referenced by audsrv_cd_play_sectors(), audsrv_quit(), cdda_procedure(), and rpc_command().

Variable Documentation

◆ cdda_initialized

int cdda_initialized = 0
static

initialization status

Definition at line 38 of file cdrom.c.

◆ cd_playing

int cd_playing = 0
static

cd status

Definition at line 40 of file cdrom.c.

Referenced by audsrv_cd_play_sectors(), audsrv_get_cdpos(), audsrv_get_trackpos(), and audsrv_stop_cd_stream().

◆ cd_paused

volatile int cd_paused = 0
static

cd is paused (but playing)

Definition at line 42 of file cdrom.c.

Referenced by audsrv_cd_pause(), audsrv_cd_resume(), and cdda_procedure().

◆ cdda_play_tid

int cdda_play_tid = -1
static

thread id for cdda player

Definition at line 44 of file cdrom.c.

Referenced by audsrv_cd_play_sectors(), and audsrv_stop_cd().

◆ cdda_pos

volatile int cdda_pos = 0
static

current sector being played

Definition at line 46 of file cdrom.c.

Referenced by audsrv_cd_play_sectors(), audsrv_get_cdpos(), audsrv_get_trackpos(), audsrv_stop_cd_stream(), and cdda_procedure().

◆ cdda_play_start

int cdda_play_start = 0
static

first sector played

Definition at line 48 of file cdrom.c.

Referenced by audsrv_cd_play_sectors(), audsrv_get_trackpos(), audsrv_stop_cd_stream(), and cdda_procedure().

◆ cdda_play_end

int cdda_play_end = 0
static

last sector to be played

Definition at line 50 of file cdrom.c.

Referenced by audsrv_cd_play_sectors(), audsrv_stop_cd_stream(), and cdda_procedure().

◆ toc

cdda_toc toc
static

toc for cdda

Definition at line 52 of file cdrom.c.

Referenced by audsrv_get_numtracks(), audsrv_get_track_offset(), audsrv_play_cd(), process_toc(), and sceCdGetToc().

◆ raw_toc

unsigned char raw_toc[3000]
static

unparsed toc data

Definition at line 54 of file cdrom.c.

Referenced by process_toc().

◆ cd_transfer_sema

int cd_transfer_sema = -1
static

SPU2 cd transfer complete semaphore

Definition at line 57 of file cdrom.c.

Referenced by cd_transfer_complete(), and cdda_procedure().

◆ cd_rendered_left

short cd_rendered_left[512]
static

Definition at line 65 of file cdrom.c.

◆ cd_rendered_right

short cd_rendered_right[512]
static

Definition at line 66 of file cdrom.c.