Skip to content

Commit

Permalink
Implement audsrv_is_adpcm_playing
Browse files Browse the repository at this point in the history
This lets you check if your sample is still playing on the given channel
  • Loading branch information
AJenbo committed Feb 11, 2023
1 parent 4620fc3 commit 9d58adf
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ee/rpc/audsrv/include/audsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ int audsrv_load_adpcm(audsrv_adpcm_t *adpcm, void *buffer, int size);
int audsrv_ch_play_adpcm(int ch, audsrv_adpcm_t *adpcm);
#define audsrv_play_adpcm(adpcm) audsrv_ch_play_adpcm(-1, adpcm) //For backward-compatibility

/** Check if a sample is currently playing on the given channel
* @returns 1 if playing, 0 if not
*/
int audsrv_is_adpcm_playing(int ch, audsrv_adpcm_t *adpcm);

/** Installs a callback function upon completion of a cdda track
* @param cb your callback
* @param arg extra parameter to pass to callback function later
Expand Down
5 changes: 5 additions & 0 deletions ee/rpc/audsrv/src/audsrv_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ int audsrv_ch_play_adpcm(int ch, audsrv_adpcm_t *adpcm)
return call_rpc_2(AUDSRV_PLAY_ADPCM, ch, (u32)adpcm);
}

int audsrv_is_adpcm_playing(int ch, audsrv_adpcm_t *adpcm)
{
return call_rpc_2(AUDSRV_IS_ADPCM_PLAYING, ch, (u32)adpcm);
}

const char *audsrv_get_error_string()
{
switch(audsrv_get_error())
Expand Down
1 change: 1 addition & 0 deletions ee/rpc/audsrv/src/audsrv_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define AUDSRV_LOAD_ADPCM 0x0017
#define AUDSRV_PLAY_ADPCM 0x0018
#define AUDSRV_ADPCM_SET_VOLUME 0x0019
#define AUDSRV_IS_ADPCM_PLAYING 0x001d

#define AUDSRV_AVAILABLE 0x001a
#define AUDSRV_QUEUED 0x001b
Expand Down
2 changes: 2 additions & 0 deletions iop/sound/audsrv/include/audsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define AUDSRV_LOAD_ADPCM 0x0017
#define AUDSRV_PLAY_ADPCM 0x0018
#define AUDSRV_SET_ADPCM_VOL 0x0019
#define AUDSRV_IS_ADPCM_PLAYING 0x001d

#define AUDSRV_AVAILABLE 0x001a
#define AUDSRV_QUEUED 0x001b
Expand Down Expand Up @@ -98,6 +99,7 @@ int audsrv_adpcm_set_volume(int ch, int voll, int volr);
void *audsrv_load_adpcm(u32 *buffer, int size, int id);
#define audsrv_play_adpcm(id) audsrv_ch_play_adpcm(-1, id) //For backward-compatibility
int audsrv_ch_play_adpcm(int ch, u32 id);
int audsrv_is_adpcm_playing(int ch, u32 id);

#define audsrv_IMPORTS_start DECLARE_IMPORT_TABLE(audsrv, 1, 4)
#define audsrv_IMPORTS_end END_IMPORT_TABLE
Expand Down
26 changes: 24 additions & 2 deletions iop/sound/audsrv/src/adpcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static adpcm_list_t *adpcm_loaded(int id)
{
adpcm_list_t *cur = adpcm_list_head;

while (cur != 0)
while (cur != NULL)
{
if (cur->id == id)
{
Expand Down Expand Up @@ -164,6 +164,28 @@ void *audsrv_load_adpcm(u32 *buffer, int size, int id)
return sbuffer;
}

int audsrv_is_adpcm_playing(int ch, u32 id)
{
u32 endx;
adpcm_list_t *a;

if (ch > 24)
return 0;

endx = sceSdGetSwitch(SD_CORE_1 | SD_SWITCH_ENDX);
if ((endx & (1 << ch)) != 0)
return 0;

a = adpcm_loaded(id);
if (a == NULL)
{
/* bad joke */
return AUDSRV_ERR_ARGS;
}

return a->spu2_addr == sceSdGetAddr(SD_CORE_1 | (ch << 1) | SD_VOICE_START);
}

static int audsrv_adpcm_alloc_channel(void)
{
int i, channel;
Expand All @@ -186,7 +208,7 @@ static int audsrv_adpcm_alloc_channel(void)
channel = i;
}

i++;
i++;
}

if (channel == -1)
Expand Down
4 changes: 4 additions & 0 deletions iop/sound/audsrv/src/rpc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ static void *rpc_command(int func, unsigned *data, int size)
ret = audsrv_ch_play_adpcm(data[0], data[1]);
break;

case AUDSRV_IS_ADPCM_PLAYING:
ret = audsrv_is_adpcm_playing(data[0], data[1]);
break;

case AUDSRV_SET_ADPCM_VOL:
ret = audsrv_adpcm_set_volume(data[0], data[1], data[2]);
break;
Expand Down

0 comments on commit 9d58adf

Please sign in to comment.