int main(int argc, char **argv) { int ret; int played; int err; char chunk[2048]; FILE *wav; struct audsrv_fmt_t format; SifInitRpc(0); printf("sample: kicking IRXs\n"); ret = SifLoadModule("rom0:LIBSD", 0, NULL); printf("libsd loadmodule %d\n", ret); printf("sample: loading audsrv\n"); ret = SifLoadModule("host:audsrv.irx", 0, NULL); printf("audsrv loadmodule %d\n", ret); ret = audsrv_init(); if (ret != 0) { printf("sample: failed to initialize audsrv\n"); printf("audsrv returned error string: %s\n", audsrv_get_error_string()); return 1; } format.bits = 16; format.freq = 22050; format.channels = 2; err = audsrv_set_format(&format); printf("set format returned %d\n", err); printf("audsrv returned error string: %s\n", audsrv_get_error_string()); audsrv_set_volume(MAX_VOLUME); wav = fopen("host:song_22k.wav", "rb"); if (wav == NULL) { printf("failed to open wav file\n"); audsrv_quit(); return 1; } fseek(wav, 0x30, SEEK_SET); printf("starting play loop\n"); played = 0; while (1) { ret = fread(chunk, 1, sizeof(chunk), wav); if (ret > 0) { audsrv_wait_audio(ret); audsrv_play_audio(chunk, ret); } if (ret < sizeof(chunk)) { /* no more data */ break; } played++; if (played % 8 == 0) { printf("."); } if (played == 512) break; } fclose(wav); printf("sample: stopping audsrv\n"); audsrv_quit(); printf("sample: ended\n"); return 0; }
/** RPC command handler. @param func command (one of AUDSRV_x) @param data pointer to data array @param size size of data array (in bytes) @returns value depends on function invoked This is a single rpc handler, it unpacks the data array and calls local functions. */ static void *rpc_command(int func, unsigned *data, int size) { int ret; /* printf("audsrv: rpc command %d\n", func); */ switch(func) { case AUDSRV_INIT: ret = audsrv_init(); break; case AUDSRV_FORMAT_OK: ret = audsrv_format_ok(data[0], data[1], data[2]); break; case AUDSRV_SET_FORMAT: ret = audsrv_set_format(data[0], data[1], data[2]); break; case AUDSRV_WAIT_AUDIO: ret = audsrv_wait_audio(data[0]); break; case AUDSRV_PLAY_AUDIO: ret = audsrv_play_audio((const char *)&data[1], data[0]); break; case AUDSRV_STOP_AUDIO: ret = audsrv_stop_audio(); break; case AUDSRV_SET_VOLUME: ret = audsrv_set_volume(data[0]); break; case AUDSRV_QUIT: ret = audsrv_quit(); break; case AUDSRV_PLAY_CD: ret = audsrv_play_cd(data[0]); break; case AUDSRV_STOP_CD: ret = audsrv_stop_cd(); break; case AUDSRV_GET_CDPOS: ret = audsrv_get_cdpos(); break; case AUDSRV_GET_TRACKPOS: ret = audsrv_get_trackpos(); break; case AUDSRV_SET_THRESHOLD: ret = audsrv_set_threshold(data[0]); break; case AUDSRV_GET_NUMTRACKS: ret = audsrv_get_numtracks(); break; case AUDSRV_GET_TRACKOFFSET: ret = audsrv_get_track_offset(data[0]); break; case AUDSRV_PLAY_SECTORS: ret = audsrv_cd_play_sectors(data[0], data[1]); break; case AUDSRV_GET_CD_STATUS: ret = audsrv_get_cd_status(); break; case AUDSRV_GET_CD_TYPE: ret = audsrv_get_cd_type(); break; case AUDSRV_PAUSE_CD: ret = audsrv_cd_pause(); break; case AUDSRV_RESUME_CD: ret = audsrv_cd_resume(); break; case AUDSRV_INIT_ADPCM: ret = audsrv_adpcm_init(); break; case AUDSRV_LOAD_ADPCM: return audsrv_load_adpcm((u32*)data[0], data[1], data[2]); case AUDSRV_PLAY_ADPCM: ret = audsrv_play_adpcm(data[0]); break; default: ret = -1; break; } data[0] = ret; return data; }
int main(int argc, char **argv) { int ret; int played; int err; int bytes; char chunk[2048]; FILE *wav; ee_sema_t sema; int fillbuffer_sema; struct audsrv_fmt_t format; SifInitRpc(0); printf("sample: kicking IRXs\n"); ret = SifLoadModule("rom0:LIBSD", 0, NULL); printf("libsd loadmodule %d\n", ret); printf("sample: loading audsrv\n"); ret = SifLoadModule("host:audsrv.irx", 0, NULL); printf("audsrv loadmodule %d\n", ret); ret = audsrv_init(); if (ret != 0) { printf("sample: failed to initialize audsrv\n"); printf("audsrv returned error string: %s\n", audsrv_get_error_string()); return 1; } format.bits = 16; format.freq = 22050; format.channels = 2; err = audsrv_set_format(&format); printf("set format returned %d\n", err); printf("audsrv returned error string: %s\n", audsrv_get_error_string()); audsrv_set_volume(MAX_VOLUME); sema.init_count = 0; sema.max_count = 1; sema.option = 0; fillbuffer_sema = CreateSema(&sema); err = audsrv_on_fillbuf(sizeof(chunk), fillbuffer, (void *)fillbuffer_sema); if (err != AUDSRV_ERR_NOERROR) { printf("audsrv_on_fillbuf failed with err=%d\n", err); goto loser; } wav = fopen("host:song_22k.wav", "rb"); if (wav == NULL) { printf("failed to open wav file\n"); audsrv_quit(); return 1; } fseek(wav, 0x30, SEEK_SET); printf("starting play loop\n"); played = 0; bytes = 0; while (1) { ret = fread(chunk, 1, sizeof(chunk), wav); if (ret > 0) { WaitSema(fillbuffer_sema); audsrv_play_audio(chunk, ret); } if (ret < sizeof(chunk)) { /* no more data */ break; } played++; bytes = bytes + ret; if (played % 8 == 0) { printf("\r%d bytes sent..", bytes); } if (played == 512) break; } fclose(wav); loser: printf("sample: stopping audsrv\n"); audsrv_quit(); printf("sample: ended\n"); return 0; }