///////////////////////////////////////////////////////////// // MAIN // ///////////////////////////////////////////////////////////// int main(int argc, char **argv) { PS2_Init(); audsrv_init(); format.bits = 16; format.freq = 44100; format.channels = 2; audsrv_set_format(&format); guiFadeOut(4); DisplayIntroBox(APP_NAME); guiFadeIn(4); guiFadeOut(4); for ( int i = 0; i < 160*144; i++ ) g_BitmapData[i] = 0; PS2_LoadButtonsConfig(ButtonsConfigPath); Load_CNF(ConfigPath); if ( SoundEnabled ) audsrv_set_volume(MAX_VOLUME); else audsrv_set_volume(MIN_VOLUME); // Main Loop while ( true ) { g_SamplePos = 0; dwKeyPad1 = 0; dwKeyPad2 = 0; if ( !auto_ROM_flag ) { MenuBrowser(); } else { // KarasQ: Here preselected ROM path is already // copied to g_FilePath (look function Load_CNF) auto_ROM_flag = 0; } int res = infogb_load_rom(g_FilePath); // KarasQ: display error and return to // browser if ROM is not loaded successfully if ( res < 1 ) { infogb_close(); } switch ( res ) { case 0: DisplayMessageBox ( "\nERROR!\n\n" "Could not load ROM\n" "Failed opening file\n" "File not found!", MSG_VOID ); continue; case -1: DisplayMessageBox ( "\nWARNING!\n\n" "Could not load ROM\n" "Unknown ROM type!", MSG_VOID ); continue; case -2: DisplayMessageBox ( "\nWARNING!\n\n" "Could not load ROM\n" "Unknown ROM size!", MSG_VOID ); continue; case -3: DisplayMessageBox ( "\nWARNING!\n\n" "Could not load ROM\n" "Unknown RAM size!", MSG_VOID ); continue; case -4: DisplayMessageBox ( "\nWARNING!\n\n" "File name of this ROM is longer\n" "than 32 characters! It's better\n" "to change it before playing!", MSG_VOID ); continue; case -5: DisplayMessageBox ( "\nERROR!\n\n" "Could not extract file archive\n", MSG_VOID ); continue; } CDVD_Stop(); infogb_init(); gameboy_cpu_hardreset(); gameboy_cpu_run(); audsrv_stop_audio(); infogb_close(); } 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; 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; }
int main(int argc, char **argv) { int i, ret; FILE* adpcm; audsrv_adpcm_t sample; int size; u8* buffer; 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; } adpcm = fopen("host:evillaugh.adp", "rb"); if (adpcm == NULL) { printf("failed to open adpcm file\n"); audsrv_quit(); return 1; } fseek(adpcm, 0, SEEK_END); size = ftell(adpcm); fseek(adpcm, 0, SEEK_SET); buffer = malloc(size); fread(buffer, 1, size, adpcm); fclose(adpcm); printf("playing sample..\n"); audsrv_adpcm_init(); audsrv_set_volume(MAX_VOLUME); audsrv_load_adpcm(&sample, buffer, size); audsrv_play_adpcm(&sample); /* Uncomment to hear two samples played simultaenously for (i=0; i<100; i++) { nopdelay(); } audsrv_play_adpcm(&sample); */ printf("sample played..\n"); free(buffer); while (1); return 0; }
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; }