Skip to content

Commit

Permalink
Cleanup sfx code
Browse files Browse the repository at this point in the history
- Remove guiDelay
- Fix guiIntroLoop
- move all audsrv* code into sound driver
  • Loading branch information
rickgaiser authored and KrahJohlito committed Jul 5, 2020
1 parent 417f20c commit f18e465
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 41 deletions.
1 change: 0 additions & 1 deletion include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void guiShowAudioConfig();
void guiShowNetConfig();
void guiShowParentalLockConfig();

void guiDelay(int milliSeconds);
void guiCheckNotifications(int checkTheme, int checkLang);

/** Renders the given string on screen for the given function until it's io finishes
Expand Down
1 change: 1 addition & 0 deletions include/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum SFX {
};

int sfxInit(int bootSnd);
void sfxEnd(void);
void sfxVolume(void);
void sfxPlay(int id);

Expand Down
28 changes: 7 additions & 21 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,6 @@ void guiShowUIConfig(void)
setDefaultColors();

applyConfig(themeID, langID);
//wait 70ms for confirm sound to finish playing before clearing buffer
guiDelay(0070);
sfxInit(0);
}

Expand Down Expand Up @@ -1382,36 +1380,24 @@ static void guiShow()
screenHandler->renderScreen();
}

void guiDelay(int milliSeconds)
{
clock_t time_end = time_end = clock() + milliSeconds * CLOCKS_PER_SEC / 1000;
while (clock() < time_end) {}

toggleSfx = 0;
}

void guiIntroLoop(void)
{
int endIntro = 0;

if (gEnableSFX && gEnableBootSND)
toggleSfx = -1;
clock_t tFadeDelayEnd = clock() + gFadeDelay * CLOCKS_PER_SEC / 1000;

while (!endIntro) {
guiStartFrame();

if (wfadeout < 0x80 && toggleSfx)
guiDelay(gFadeDelay);

if (wfadeout < 0x80 && !toggleSfx)
if (wfadeout < 0x80)
guiShow();

if (gInitComplete)
wfadeout -= 0x02;

if (wfadeout > 0)
guiRenderGreeting();
else

if (gInitComplete && clock() >= tFadeDelayEnd)
wfadeout -= 0x02;

if (wfadeout <= 0)
endIntro = 1;

guiDrawOverlays();
Expand Down
21 changes: 6 additions & 15 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
int configGetStat(config_set_t *configSet, iox_stat_t *stat);

#include <unistd.h>
#include <audsrv.h>
#ifdef PADEMU
#include <libds34bt.h>
#include <libds34usb.h>
Expand Down Expand Up @@ -1260,7 +1259,7 @@ static int loadHdldSvr(void)
}

// deint audio lib while hdl server is running
audsrv_quit();
sfxEnd();

// block all io ops, wait for the ones still running to finish
ioBlockOps(1);
Expand Down Expand Up @@ -1376,11 +1375,6 @@ void deinit(int exception, int modeSelected)
ioBlockOps(1);
guiExecDeferredOps();

if (gEnableSFX) {
gEnableSFX = 0;
}
audsrv_quit();

#ifdef PADEMU
ds34usb_reset();
ds34bt_reset();
Expand All @@ -1389,6 +1383,7 @@ void deinit(int exception, int modeSelected)

deinitAllSupport(exception, modeSelected);

sfxEnd();
ioEnd();
guiEnd();
menuEnd();
Expand Down Expand Up @@ -1551,16 +1546,12 @@ static void deferredAudioInit(void)
{
int ret;

ret = audsrv_init();
if (ret != 0)
LOG("Failed to initialize audsrv\n");
LOG("Audsrv returned error string: %s\n", audsrv_get_error_string());

ret = sfxInit(1);
if (ret >= 0)
LOG("sfxInit: %d samples loaded.\n", ret);
else
if (ret < 0) {
LOG("sfxInit: failed to initialize - %d.\n", ret);
return;
}
LOG("sfxInit: %d samples loaded.\n", ret);

// boot sound
if (gEnableBootSND) {
Expand Down
13 changes: 13 additions & 0 deletions src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ int sfxInit(int bootSnd)
int thmSfxEnabled = 0;
int i = 1;

if (audsrv_init() != 0) {
LOG("Failed to initialize audsrv\n");
LOG("Audsrv returned error string: %s\n", audsrv_get_error_string());
return -1;
}

audsrv_adpcm_init();

sfxInitDefaults();
Expand Down Expand Up @@ -228,6 +234,13 @@ int sfxInit(int bootSnd)
return loaded;
}

void sfxEnd()
{
if (gEnableSFX) {
audsrv_quit();
}
}

void sfxPlay(int id)
{
if (gEnableSFX) {
Expand Down
4 changes: 0 additions & 4 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,6 @@ int sysGetDiscID(char *hexDiscID)

void sysExecExit(void)
{
if (gEnableSFX) {
//wait 70ms for confirm sound to finish playing before exit
guiDelay(0070);
}
//Deinitialize without shutting down active devices.
deinit(NO_EXCEPTION, IO_MODE_SELECTED_ALL);
Exit(0);
Expand Down

0 comments on commit f18e465

Please sign in to comment.