ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
ahx_rpc.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AHX_IRX   0xC001D0E
 
#define AHX_INIT   0x01
 
#define AHX_PLAY   0x02
 
#define AHX_PAUSE   0x03
 
#define AHX_QUIT   0x04
 
#define AHX_LOADSONG   0x05
 
#define AHX_SETVOLUME   0x06
 
#define AHX_SETBOOST   0x07
 
#define AHX_OVERSAMPLING   0x08
 
#define AHX_SUBSONG   0x09
 

Functions

int AHX_Init ()
 
int AHX_LoadSongBuffer (char *songdata, int songsize)
 
int AHX_LoadSong (char *filename)
 
int AHX_SubSong (int songNo)
 
int AHX_SetVolume (int volumePercentage)
 
int AHX_SetBoost (int boostValue)
 
int AHX_ToggleOversampling ()
 
int AHX_Quit ()
 
int AHX_Play ()
 
int AHX_Pause ()
 

Detailed Description

AHX EE-side RPC code.

Definition in file ahx_rpc.h.

Macro Definition Documentation

◆ AHX_INIT

#define AHX_INIT   0x01

Definition at line 20 of file ahx_rpc.h.

◆ AHX_IRX

#define AHX_IRX   0xC001D0E

Definition at line 19 of file ahx_rpc.h.

◆ AHX_LOADSONG

#define AHX_LOADSONG   0x05

Definition at line 24 of file ahx_rpc.h.

◆ AHX_OVERSAMPLING

#define AHX_OVERSAMPLING   0x08

Definition at line 27 of file ahx_rpc.h.

◆ AHX_PAUSE

#define AHX_PAUSE   0x03

Definition at line 22 of file ahx_rpc.h.

◆ AHX_PLAY

#define AHX_PLAY   0x02

Definition at line 21 of file ahx_rpc.h.

◆ AHX_QUIT

#define AHX_QUIT   0x04

Definition at line 23 of file ahx_rpc.h.

◆ AHX_SETBOOST

#define AHX_SETBOOST   0x07

Definition at line 26 of file ahx_rpc.h.

◆ AHX_SETVOLUME

#define AHX_SETVOLUME   0x06

Definition at line 25 of file ahx_rpc.h.

◆ AHX_SUBSONG

#define AHX_SUBSONG   0x09

Definition at line 28 of file ahx_rpc.h.

Function Documentation

◆ AHX_Init()

int AHX_Init ( )

AHX Init

Sends a call the the loaded AHX IRX, telling it to set things up ready for loading a song.

Definition at line 48 of file ahx_rpc.c.

49 {
50  int i;
51  // struct t_SifDmaTransfer sdt;
52 
53  // if already init'd, exit
54  if (ahx_init_done) return 0;
55 
56  // bind rpc
57  while(1){
58  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1; // bind error
59  if (cd0.server != 0) break;
60  i = 0x10000;
61  while(i--);
62  }
63 
64  SifCallRpc(&cd0,AHX_INIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
65 
66  songbuffer_addr = (char*)sbuff[1];
67 
68  // set flag, init done
69  ahx_init_done = 1;
70  return 0;
71 }
static struct t_SifRpcClientData cd0
Definition: ahx_rpc.c:28
static unsigned sbuff[64]
Definition: ahx_rpc.c:27
int ahx_init_done
Definition: ahx_rpc.c:32
char * songbuffer_addr
Definition: ahx_rpc.c:31
#define AHX_INIT
Definition: ahx_rpc.h:20
#define AHX_IRX
Definition: ahx_rpc.h:19
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
#define NULL
Definition: tamtypes.h:91

References AHX_INIT, ahx_init_done, AHX_IRX, cd0, NULL, sbuff, SifBindRpc(), SifCallRpc(), and songbuffer_addr.

◆ AHX_LoadSong()

int AHX_LoadSong ( char *  filename)

AHX LongSongBuffer

This loads a song from disk etc. It loads the songdata into memory and passes it to LongSongBuffer.

Returns
number of subsongs.

Definition at line 191 of file ahx_rpc.c.

192 {
193  int fd, fdSize;
194  char* buffer;
195 
196  fd = open(filename, O_RDONLY);
197  if(fd < 0)
198  {
199  printf("ERROR LOADING SONG\n");
200  return -1;
201  }
202  fdSize = lseek(fd, 0, SEEK_END);
203  lseek(fd, 0, SEEK_SET);
204  buffer = malloc(fdSize);
205  if(!buffer)
206  {
207  printf("ERROR ALLOCATING SONG MEMORY SONG\n");
208  return -1;
209  }
210  read(fd, buffer, fdSize);
211  close(fd);
212  return AHX_LoadSongBuffer(buffer, fdSize);
213 }
int AHX_LoadSongBuffer(char *songdata, int songsize)
Definition: ahx_rpc.c:167
u8 buffer[128]
Definition: rpc_client.c:19

References AHX_LoadSongBuffer(), and buffer.

◆ AHX_LoadSongBuffer()

int AHX_LoadSongBuffer ( char *  songdata,
int  songsize 
)

AHX LongSongBuffer

This loads a song from a buffer in memory. It copies [songsize] bytes from [songdata] to the IOP memory song buffer.

Returns
number of subsongs.

Definition at line 167 of file ahx_rpc.c.

168 {
169  int i;
170 
171  // write song data to IOP song buffer
172  iop_readwrite(songbuffer_addr, songdata, songsize, 0);
173 
174  while(1){
175  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
176  if (cd0.server != 0) break;
177  i = 0x10000;
178  while(i--);
179  }
180 
181  // set oversample and boost
182  sbuff[0] = (unsigned)songsize;
183 
184  // call rpc
185  SifCallRpc(&cd0,AHX_LOADSONG,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
186 
187  // return number of sub-songs
188  return (int)sbuff[1];
189 }
void iop_readwrite(void *addr, void *buf, u32 size, u32 read)
Definition: ahx_rpc.c:39
#define AHX_LOADSONG
Definition: ahx_rpc.h:24

References AHX_IRX, AHX_LOADSONG, cd0, iop_readwrite(), NULL, sbuff, SifBindRpc(), SifCallRpc(), and songbuffer_addr.

Referenced by AHX_LoadSong().

◆ AHX_Pause()

int AHX_Pause ( )

AHX Pause

Sends a call the the loaded AHX IRX, telling it to pause the currently loaded song.

Definition at line 86 of file ahx_rpc.c.

87 {
88  int i;
89  while(1){
90  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
91  if (cd0.server != 0) break;
92  i = 0x10000;
93  while(i--);
94  }
95  SifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
96  return 0;
97 }
#define AHX_PAUSE
Definition: ahx_rpc.h:22

References AHX_IRX, AHX_PAUSE, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_Play()

int AHX_Play ( )

AHX Play

Sends a call the the loaded AHX IRX, telling it to play the currently loaded song.

Definition at line 73 of file ahx_rpc.c.

74 {
75  int i;
76  while(1){
77  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
78  if (cd0.server != 0) break;
79  i = 0x10000;
80  while(i--);
81  }
82  SifCallRpc(&cd0,AHX_PLAY,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
83  return 0;
84 }
#define AHX_PLAY
Definition: ahx_rpc.h:21

References AHX_IRX, AHX_PLAY, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_Quit()

int AHX_Quit ( )

AHX Quit

Sends a call the the loaded AHX IRX, telling it to quit. This frees up IOP mem, quites threads, deletes semaphores and all that jazz....

Definition at line 154 of file ahx_rpc.c.

155 {
156  int i;
157  while(1){
158  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
159  if (cd0.server != 0) break;
160  i = 0x10000;
161  while(i--);
162  }
163  SifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
164  return 0;
165 }
#define AHX_QUIT
Definition: ahx_rpc.h:23

References AHX_IRX, AHX_QUIT, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_SetBoost()

int AHX_SetBoost ( int  boostValue)

AHX Set Boost

Sends a call the the loaded AHX IRX, telling it to change the output boost value. Boost value multiplies the level of the output for the AHX Mixer. A boost value of 1 is twice as load as a boost value of 0. A boost value of 3 is twice as load as 2 etc etc (ala DB)

Definition at line 127 of file ahx_rpc.c.

128 {
129  int i;
130  while(1){
131  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
132  if (cd0.server != 0) break;
133  i = 0x10000;
134  while(i--);
135  }
136  sbuff[0] = (unsigned)boostValue;
137  SifCallRpc(&cd0,AHX_SETBOOST,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
138  return 0;
139 }
#define AHX_SETBOOST
Definition: ahx_rpc.h:26

References AHX_IRX, AHX_SETBOOST, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_SetVolume()

int AHX_SetVolume ( int  volumePercentage)

AHX Set Volume

Sends a call the the loaded AHX IRX, telling it to change the output volume of the SPU2. volumePercentage argument can range from 0 (0% silence) to 100 (100% full volume)

Definition at line 113 of file ahx_rpc.c.

114 {
115  int i;
116  while(1){
117  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
118  if (cd0.server != 0) break;
119  i = 0x10000;
120  while(i--);
121  }
122  sbuff[0] = (unsigned)volumePercentage;
123  SifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
124  return 0;
125 }

References AHX_IRX, AHX_QUIT, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_SubSong()

int AHX_SubSong ( int  songNo)

AHX Play Subsong

Sends a call the the loaded AHX IRX, telling it to load subsong (songNo). You can determine the number of subsongs by checking the values returned by AHX_LoadSong() and AHX_LoadSongBuffer();

Definition at line 99 of file ahx_rpc.c.

100 {
101  int i;
102  while(1){
103  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
104  if (cd0.server != 0) break;
105  i = 0x10000;
106  while(i--);
107  }
108  sbuff[0] = (unsigned)songNo;
109  SifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
110  return 0;
111 }

References AHX_IRX, AHX_PAUSE, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().

◆ AHX_ToggleOversampling()

int AHX_ToggleOversampling ( )

AHX Toggle Oversampling

Switches oversampling on/off. Oversampling produces a smoother output sound but uses a lot more CPU power. It sounds nasty/slows down for a lot of songs - use with caution (or not at all)

Definition at line 141 of file ahx_rpc.c.

142 {
143  int i;
144  while(1){
145  if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
146  if (cd0.server != 0) break;
147  i = 0x10000;
148  while(i--);
149  }
150  SifCallRpc(&cd0,AHX_OVERSAMPLING,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
151  return 0;
152 }
#define AHX_OVERSAMPLING
Definition: ahx_rpc.h:27

References AHX_IRX, AHX_OVERSAMPLING, cd0, NULL, sbuff, SifBindRpc(), and SifCallRpc().