ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
playwav.c File Reference
#include <stdio.h>
#include <string.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <tamtypes.h>
#include <audsrv.h>
+ Include dependency graph for playwav.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file playwav.c.

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)
void SifInitRpc(int mode)
#define NULL
Definition: tamtypes.h:91

References audsrv_get_error_string(), audsrv_init(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), audsrv_set_volume(), audsrv_wait_audio(), audsrv_fmt_t::bits, audsrv_fmt_t::channels, audsrv_fmt_t::freq, MAX_VOLUME, NULL, SifInitRpc(), and SifLoadModule().