Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement audsrv_is_adpcm_playing #407

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

/** Remove an adpcm sample uploaded with audsrv_load_adpcm() from the list of loaded sounds
* @param id sample identifier, as specified in load()
*
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);
}

int audsrv_free_adpcm(audsrv_adpcm_t *adpcm)
{
/* on iop side, the sample id is like the pointer on ee side */
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 @@ -52,6 +52,7 @@
#define AUDSRV_PLAY_ADPCM 0x0018
#define AUDSRV_ADPCM_SET_VOLUME 0x0019
#define AUDSRV_FREE_ADPCM 0x001c
#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 @@ -49,6 +49,7 @@
#define AUDSRV_PLAY_ADPCM 0x0018
#define AUDSRV_SET_ADPCM_VOL 0x0019
#define AUDSRV_FREE_ADPCM 0x001c
#define AUDSRV_IS_ADPCM_PLAYING 0x001d

#define AUDSRV_AVAILABLE 0x001a
#define AUDSRV_QUEUED 0x001b
Expand Down Expand Up @@ -99,6 +100,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);
int free_sample(u32 id);

#define audsrv_IMPORTS_start DECLARE_IMPORT_TABLE(audsrv, 1, 4)
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 @@ -126,7 +126,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 @@ -207,6 +207,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 @@ -229,7 +251,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_FREE_ADPCM:
ret = free_sample(data[0]);
break;
Expand Down