ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
playwav2.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 playwav2.c:

Go to the source code of this file.

Functions

static int fillbuffer (void *arg)
 
int main (int argc, char **argv)
 

Function Documentation

◆ fillbuffer()

static int fillbuffer ( void *  arg)
static

Definition at line 23 of file playwav2.c.

24 {
25  iSignalSema((int)arg);
26  return 0;
27 }
s32 iSignalSema(s32 sema_id)

References iSignalSema().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file playwav2.c.

30 {
31  int ret;
32  int played;
33  int err;
34  int bytes;
35  char chunk[2048];
36  FILE *wav;
37  ee_sema_t sema;
38  int fillbuffer_sema;
39  struct audsrv_fmt_t format;
40 
41  SifInitRpc(0);
42 
43  printf("sample: kicking IRXs\n");
44  ret = SifLoadModule("rom0:LIBSD", 0, NULL);
45  printf("libsd loadmodule %d\n", ret);
46 
47  printf("sample: loading audsrv\n");
48  ret = SifLoadModule("host:audsrv.irx", 0, NULL);
49  printf("audsrv loadmodule %d\n", ret);
50 
51  ret = audsrv_init();
52  if (ret != 0)
53  {
54  printf("sample: failed to initialize audsrv\n");
55  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
56  return 1;
57  }
58 
59  format.bits = 16;
60  format.freq = 22050;
61  format.channels = 2;
62  err = audsrv_set_format(&format);
63  printf("set format returned %d\n", err);
64  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
65 
67 
68  sema.init_count = 0;
69  sema.max_count = 1;
70  sema.option = 0;
71  fillbuffer_sema = CreateSema(&sema);
72 
73  err = audsrv_on_fillbuf(sizeof(chunk), fillbuffer, (void *)fillbuffer_sema);
74  if (err != AUDSRV_ERR_NOERROR)
75  {
76  printf("audsrv_on_fillbuf failed with err=%d\n", err);
77  goto loser;
78  }
79 
80  wav = fopen("host:song_22k.wav", "rb");
81  if (wav == NULL)
82  {
83  printf("failed to open wav file\n");
84  audsrv_quit();
85  return 1;
86  }
87 
88  fseek(wav, 0x30, SEEK_SET);
89 
90  printf("starting play loop\n");
91  played = 0;
92  bytes = 0;
93  while (1)
94  {
95  ret = fread(chunk, 1, sizeof(chunk), wav);
96  if (ret > 0)
97  {
98  WaitSema(fillbuffer_sema);
99  audsrv_play_audio(chunk, ret);
100  }
101 
102  if (ret < sizeof(chunk))
103  {
104  /* no more data */
105  break;
106  }
107 
108  played++;
109  bytes = bytes + ret;
110 
111  if (played % 8 == 0)
112  {
113  printf("\r%d bytes sent..", bytes);
114  }
115 
116  if (played == 512) break;
117  }
118 
119  fclose(wav);
120 
121 loser:
122  printf("sample: stopping audsrv\n");
123  audsrv_quit();
124 
125  printf("sample: ended\n");
126  return 0;
127 }
const char * audsrv_get_error_string()
Definition: audsrv_rpc.c:438
int audsrv_init()
Definition: audsrv_rpc.c:296
#define AUDSRV_ERR_NOERROR
Definition: audsrv.h:28
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_on_fillbuf(int amount, audsrv_callback_t cb, void *arg)
Definition: audsrv_rpc.c:471
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)
s32 CreateSema(ee_sema_t *sema)
s32 WaitSema(s32 sema_id)
static int fillbuffer(void *arg)
Definition: playwav2.c:23
void SifInitRpc(int mode)
int init_count
Definition: kernel.h:218
int max_count
Definition: kernel.h:217
u32 option
Definition: kernel.h:221
#define NULL
Definition: tamtypes.h:91

References AUDSRV_ERR_NOERROR, audsrv_get_error_string(), audsrv_init(), audsrv_on_fillbuf(), audsrv_play_audio(), audsrv_quit(), audsrv_set_format(), audsrv_set_volume(), audsrv_fmt_t::bits, audsrv_fmt_t::channels, CreateSema(), fillbuffer(), audsrv_fmt_t::freq, ee_sema_t::init_count, ee_sema_t::max_count, MAX_VOLUME, NULL, ee_sema_t::option, SifInitRpc(), SifLoadModule(), and WaitSema().