ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
playadpcm.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 adpcm sample
11 */
12 #include <stdio.h>
13 #include <string.h>
14 
15 #include <kernel.h>
16 #include <sifrpc.h>
17 #include <loadfile.h>
18 #include <tamtypes.h>
19 
20 #include <audsrv.h>
21 
22 int main(int argc, char **argv)
23 {
24  /* Uncomment to hear two samples played simultaenously
25  int i;
26  */
27  int ret;
28  FILE* adpcm;
29  audsrv_adpcm_t sample;
30  int size;
31  u8* buffer;
32 
33  SifInitRpc(0);
34 
35  printf("sample: kicking IRXs\n");
36  ret = SifLoadModule("rom0:LIBSD", 0, NULL);
37  printf("libsd loadmodule %d\n", ret);
38 
39  printf("sample: loading audsrv\n");
40  ret = SifLoadModule("host:audsrv.irx", 0, NULL);
41  printf("audsrv loadmodule %d\n", ret);
42 
43  ret = audsrv_init();
44  if (ret != 0)
45  {
46  printf("sample: failed to initialize audsrv\n");
47  printf("audsrv returned error string: %s\n", audsrv_get_error_string());
48  return 1;
49  }
50 
51  adpcm = fopen("host:evillaugh.adp", "rb");
52 
53  if (adpcm == NULL)
54  {
55  printf("failed to open adpcm file\n");
56  audsrv_quit();
57  return 1;
58  }
59 
60  fseek(adpcm, 0, SEEK_END);
61  size = ftell(adpcm);
62  fseek(adpcm, 0, SEEK_SET);
63 
64  buffer = malloc(size);
65 
66  fread(buffer, 1, size, adpcm);
67  fclose(adpcm);
68 
69  printf("playing sample..\n");
70 
74  audsrv_load_adpcm(&sample, buffer, size);
75  audsrv_ch_play_adpcm(0, &sample);
76 
77  /* Uncomment to hear two samples played simultaenously
78  for (i=0; i<100; i++)
79  {
80  nopdelay();
81  }
82 
83  audsrv_adpcm_set_volume(1, MAX_VOLUME);
84  audsrv_ch_play_adpcm(1, &sample);
85  */
86 
87  printf("sample played..\n");
88 
89  free(buffer);
90 
91  while (1);
92  return 0;
93 }
const char * audsrv_get_error_string()
Definition: audsrv_rpc.c:438
int audsrv_init()
Definition: audsrv_rpc.c:296
int audsrv_adpcm_init()
Definition: audsrv_rpc.c:362
int audsrv_adpcm_set_volume(int ch, int vol)
Definition: audsrv_rpc.c:367
int audsrv_ch_play_adpcm(int ch, audsrv_adpcm_t *adpcm)
Definition: audsrv_rpc.c:432
#define MAX_VOLUME
Definition: audsrv.h:25
int audsrv_load_adpcm(audsrv_adpcm_t *adpcm, void *buffer, int size)
Definition: audsrv_rpc.c:381
int audsrv_set_volume(int volume)
Definition: audsrv_rpc.c:157
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: playadpcm.c:22
u8 buffer[128]
Definition: rpc_client.c:19
void SifInitRpc(int mode)
#define NULL
Definition: tamtypes.h:91
unsigned char u8
Definition: tamtypes.h:23