ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
playwav.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 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 int main(int argc, char **argv)
24 {
25  int ret;
26  int played;
27  int err;
28  char chunk[2048];
29  FILE *wav;
30  struct audsrv_fmt_t format;
31 
32  SifInitRpc(0);
33 
34  printf("sample: kicking IRXs\n");
35  ret = SifLoadModule("rom0:LIBSD", 0, NULL);
36  printf("libsd loadmodule %d\n", ret);
37 
38  printf("sample: loading audsrv\n");
39  ret = SifLoadModule("host:audsrv.irx", 0, NULL);
40  printf("audsrv loadmodule %d\n", ret);
41 
42  ret = audsrv_init();
43  if (ret != 0)
44  {
45  printf("sample: failed to initialize audsrv\n");
46  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
47  return 1;
48  }
49 
50  format.bits = 16;
51  format.freq = 22050;
52  format.channels = 2;
53  err = audsrv_set_format(&format);
54  printf("set format returned %d\n", err);
55  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
56 
58 
59  wav = fopen("host:song_22k.wav", "rb");
60  if (wav == NULL)
61  {
62  printf("failed to open wav file\n");
63  audsrv_quit();
64  return 1;
65  }
66 
67  fseek(wav, 0x30, SEEK_SET);
68 
69  printf("starting play loop\n");
70  played = 0;
71  while (1)
72  {
73  ret = fread(chunk, 1, sizeof(chunk), wav);
74  if (ret > 0)
75  {
76  audsrv_wait_audio(ret);
77  audsrv_play_audio(chunk, ret);
78  }
79 
80  if (ret < sizeof(chunk))
81  {
82  /* no more data */
83  break;
84  }
85 
86  played++;
87  if (played % 8 == 0)
88  {
89  printf(".");
90  }
91 
92  if (played == 512) break;
93  }
94 
95  fclose(wav);
96 
97  printf("sample: stopping audsrv\n");
98  audsrv_quit();
99 
100  printf("sample: ended\n");
101  return 0;
102 }
const char * audsrv_get_error_string()
Definition: audsrv_rpc.c:438
int audsrv_init()
Definition: audsrv_rpc.c:296
int audsrv_play_audio(const char *chunk, int bytes)
Definition: audsrv_rpc.c:228
#define MAX_VOLUME
Definition: audsrv.h:25
int audsrv_set_volume(int volume)
Definition: audsrv_rpc.c:157
int audsrv_wait_audio(int bytes)
Definition: audsrv_rpc.c:152
int audsrv_set_format(struct audsrv_fmt_t *fmt)
Definition: audsrv_rpc.c:133
int audsrv_quit()
Definition: audsrv_rpc.c:117
int SifLoadModule(const char *path, int arg_len, const char *args)
int main(int argc, char **argv)
Definition: playwav.c:23
void SifInitRpc(int mode)
int bits
Definition: audsrv.h:46
int freq
Definition: audsrv.h:44
int channels
Definition: audsrv.h:48
#define NULL
Definition: tamtypes.h:91