ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
playcdda.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2005, ps2dev - http://www.ps2dev.org
7 # Licenced under GNU Library General Public License version 2
8 # Review ps2sdk README & LICENSE files for further details.
9 #
10 # audsrv cdda sample
11 */
12 
13 #include <stdio.h>
14 #include <string.h>
15 
16 #include <kernel.h>
17 #include <sifrpc.h>
18 #include <loadfile.h>
19 #include <tamtypes.h>
20 
21 #include <audsrv.h>
22 
23 static volatile int track_ended = 0;
24 
25 static void cdda_stopped(void *arg)
26 {
27  track_ended = 1;
28 }
29 
30 int main(int argc, char **argv)
31 {
32  int ret;
33  int track;
34  int lastpos;
35 
36  SifInitRpc(0);
37 
38  printf("sample: kicking IRXs\n");
39  ret = SifLoadModule("rom0:LIBSD", 0, NULL);
40  printf("libsd loadmodule %d\n", ret);
41 
42  printf("sample: loading audsrv\n");
43  ret = SifLoadModule("host:audsrv.irx", 0, NULL);
44  printf("audsrv loadmodule %d\n", ret);
45 
46  ret = audsrv_init();
47  if (ret != 0)
48  {
49  printf("sample: failed to initialize audsrv\n");
50  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
51  return 1;
52  }
53 
54  printf("setting callback\n");
56 
57  track = 4;
58  printf("playing track %d\n", track);
59  audsrv_play_cd(track);
60 
61  //printf("starting loop\n");
62 
63  lastpos = 0;
64  while (track_ended == 0)
65  {
66  int pos;
67 
68  if (audsrv_get_cdpos() == 0)
69  {
70  printf("-- track ended before semaphore --\n");
71  break;
72  }
73 
75  nopdelay();
76 
77  if (lastpos != pos)
78  {
79  printf("\rTrack %02d: %02d:%02d:%02d",
80  track, pos / (75*60), (pos / 75) % 60, pos % 75);
81  lastpos = pos;
82  }
83  }
84 
85  printf("\n");
86  printf("track ended\n");
87 
88  audsrv_quit();
89  printf("sample: ended\n");
90  return 0;
91 }
const char * audsrv_get_error_string()
Definition: audsrv_rpc.c:438
int audsrv_init()
Definition: audsrv_rpc.c:296
int audsrv_on_cdda_stop(audsrv_callback_t cb, void *arg)
Definition: audsrv_rpc.c:464
int audsrv_play_cd(int track)
Definition: audsrv_rpc.c:171
int audsrv_get_trackpos()
Definition: audsrv_rpc.c:193
int audsrv_get_cdpos()
Definition: audsrv_rpc.c:188
int audsrv_quit()
Definition: audsrv_rpc.c:117
int SifLoadModule(const char *path, int arg_len, const char *args)
static void nopdelay(void)
Definition: kernel.h:141
struct @29::@30 pos
static void cdda_stopped(void *arg)
Definition: playcdda.c:25
int main(int argc, char **argv)
Definition: playcdda.c:30
static volatile int track_ended
Definition: playcdda.c:23
void SifInitRpc(int mode)
#define NULL
Definition: tamtypes.h:91