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

Ogg vorbis supported theme background music #836

Merged
merged 4 commits into from
Dec 9, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ PNG_ASSETS_DIR = gfx/
MAPFILE = opl.map
EE_LDFLAGS += -Wl,-Map,$(MAPFILE)

EE_LIBS = -L$(PS2SDK)/ports/lib -L$(GSKIT)/lib -L./lib -lgskit -ldmakit -lgskit_toolkit -lpoweroff -lfileXio -lpatches -ljpeg_ps2_addons -ljpeg -lpng -lz -ldebug -lm -lmc -lfreetype -lvux -lcdvd -lnetman -lps2ips -laudsrv -lpadx -lelf-loader
EE_LIBS = -L$(PS2SDK)/ports/lib -L$(GSKIT)/lib -L./lib -lgskit -ldmakit -lgskit_toolkit -lpoweroff -lfileXio -lpatches -ljpeg_ps2_addons -ljpeg -lpng -lz -ldebug -lm -lmc -lfreetype -lvux -lcdvd -lnetman -lps2ips -laudsrv -lvorbisfile -lvorbis -logg -lpadx -lelf-loader
EE_INCS += -I$(PS2SDK)/ports/include -I$(PS2SDK)/ports/include/freetype2 -I$(GSKIT)/include -I$(GSKIT)/ee/dma/include -I$(GSKIT)/ee/gs/include -I$(GSKIT)/ee/toolkit/include -Imodules/iopcore/common -Imodules/network/common -Imodules/hdd/common -Iinclude

BIN2C = $(PS2SDK)/bin/bin2c
Expand Down
3 changes: 3 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ enum CONFIG_INDEX {
#define CONFIG_OPL_PARENTAL_LOCK_PWD "parental_lock_password"
#define CONFIG_OPL_SFX "enable_sfx"
#define CONFIG_OPL_BOOT_SND "enable_boot_snd"
#define CONFIG_OPL_BGM "enable_bgm"
#define CONFIG_OPL_SFX_VOLUME "sfx_volume"
#define CONFIG_OPL_BOOT_SND_VOLUME "boot_snd_volume"
#define CONFIG_OPL_BGM_VOLUME "bgm_volume"
#define CONFIG_OPL_DEFAULT_BGM_PATH "default_bgm_path"

// Network config keys
#define CONFIG_NET_ETH_LINKM "eth_linkmode"
Expand Down
3 changes: 3 additions & 0 deletions include/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ enum UI_ITEMS {

CFG_SFX,
CFG_BOOT_SND,
CFG_BGM,
CFG_SFX_VOLUME,
CFG_BOOT_SND_VOLUME,
CFG_BGM_VOLUME,
CFG_DEFAULT_BGM_PATH,

NETCFG_SHOW_ADVANCED_OPTS,
NETCFG_PS2_IP_ADDR_TYPE,
Expand Down
3 changes: 3 additions & 0 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ extern int gHDDGameListCache;

extern int gEnableSFX;
extern int gEnableBootSND;
extern int gEnableBGM;
extern int gSFXVolume;
extern int gBootSndVolume;
extern int gBGMVolume;
extern char gDefaultBGMPath[128];

extern int gCheatSource;
extern int gGSMSource;
Expand Down
12 changes: 10 additions & 2 deletions include/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ enum SFX {
SFX_COUNT
};

void audioInit(void);
void audioEnd(void);
void audioSetVolume(void);

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

void bgmStart(void);
void bgmStop(void);
int isBgmPlaying(void);
void bgmMute(void);
void bgmUnMute(void);

#endif
8 changes: 8 additions & 0 deletions lng_tmpl/_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,11 @@ gui_strings:
string: OSD Language
- label: ENABLE_LNG
string: Change language
- label: BGM
string: Background Music
- label: BGM_VOLUME
string: Background Music Volume
- label: DEF_BGM_PATH
string: Default Theme Music
- label: DEF_BGM_PATH_HINT
string: Set path to stream music for internal theme.
3 changes: 3 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "include/opl.h"
#include "include/util.h"
#include "include/ioman.h"
#include "include/sound.h"
#include <string.h>

// FIXME: We should not need this function.
Expand Down Expand Up @@ -544,6 +545,7 @@ int configWrite(config_set_t *configSet)
if (fileBuffer) {
char line[512];

bgmMute();
struct config_value_t *cur = configSet->head;
while (cur) {
if ((cur->key[0] != '\0') && (cur->key[0] != '#')) {
Expand All @@ -557,6 +559,7 @@ int configWrite(config_set_t *configSet)

closeFileBuffer(fileBuffer);
configSet->modified = 0;
bgmUnMute();
return 1;
}
return 0;
Expand Down
17 changes: 16 additions & 1 deletion src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ struct UIItem diaAbout[] = {
{UI_BREAK},

{UI_SPACER},
{UI_LABEL, 0, 1, 1, -1, 0, 15, {.label = {"hominem.te.esse - ifcaro - izdubar - jimmikaelkael", -1}}},
{UI_LABEL, 0, 1, 1, -1, 0, 15, {.label = {"hominem.te.esse - ifcaro - izdubar - jimmikaelkael - KrahJohlito", -1}}},
{UI_BREAK},

{UI_SPACER},
Expand Down Expand Up @@ -968,6 +968,11 @@ struct UIItem diaAudioConfig[] = {
{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_BOOT_SND}}},
{UI_SPACER},
{UI_BOOL, CFG_BOOT_SND, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_BGM}}},
{UI_SPACER},
{UI_BOOL, CFG_BGM, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_SFX_VOLUME}}},
Expand All @@ -980,6 +985,16 @@ struct UIItem diaAudioConfig[] = {
{UI_INT, CFG_BOOT_SND_VOLUME, 1, 1, -1, 0, 0, {.intvalue = {0, 0, 0, 100}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_BGM_VOLUME}}},
{UI_SPACER},
{UI_INT, CFG_BGM_VOLUME, 1, 1, -1, 0, 0, {.intvalue = {0, 0, 0, 100}}},
{UI_SPLITTER},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_DEF_BGM_PATH}}},
{UI_SPACER},
{UI_STRING, CFG_DEFAULT_BGM_PATH, 1, 1, _STR_DEF_BGM_PATH_HINT, 0, 0, {.stringvalue = {"", "", NULL}}},
{UI_BREAK},

// buttons
{UI_OK, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_OK}}},
{UI_BREAK},
Expand Down
22 changes: 21 additions & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,11 @@ void guiShowUIConfig(void)
, NULL};
// clang-format on
int previousVMode;
int previousTheme;

reselect_video_mode:
previousVMode = gVMode;
previousTheme = thmGetGuiValue();
diaSetEnum(diaUIConfig, UICFG_THEME, (const char **)thmGetGuiList());
diaSetEnum(diaUIConfig, UICFG_LANG, (const char **)lngGetGuiList());
diaSetEnum(diaUIConfig, UICFG_VMODE, vmodeNames);
Expand Down Expand Up @@ -664,8 +666,14 @@ void guiShowUIConfig(void)
if (ret == UICFG_RESETCOL)
setDefaultColors();

if (previousTheme != themeID && isBgmPlaying())
bgmStop();

applyConfig(themeID, langID);
sfxInit(0);

if (gEnableBGM && !isBgmPlaying())
bgmStart();
}

if (previousVMode != gVMode) {
Expand Down Expand Up @@ -828,9 +836,15 @@ static void guiSetAudioSettingsState(void)
{
diaGetInt(diaAudioConfig, CFG_SFX, &gEnableSFX);
diaGetInt(diaAudioConfig, CFG_BOOT_SND, &gEnableBootSND);
diaGetInt(diaAudioConfig, CFG_BGM, &gEnableBGM);
diaGetInt(diaAudioConfig, CFG_SFX_VOLUME, &gSFXVolume);
diaGetInt(diaAudioConfig, CFG_BOOT_SND_VOLUME, &gBootSndVolume);
sfxVolume();
diaGetInt(diaAudioConfig, CFG_BGM_VOLUME, &gBGMVolume);
diaGetString(diaAudioConfig, CFG_DEFAULT_BGM_PATH, gDefaultBGMPath, sizeof(gDefaultBGMPath));
audioSetVolume();

if (gEnableBGM && !isBgmPlaying())
bgmStart();
}

static int guiAudioUpdater(int modified)
Expand All @@ -846,8 +860,11 @@ void guiShowAudioConfig(void)
{
diaSetInt(diaAudioConfig, CFG_SFX, gEnableSFX);
diaSetInt(diaAudioConfig, CFG_BOOT_SND, gEnableBootSND);
diaSetInt(diaAudioConfig, CFG_BGM, gEnableBGM);
diaSetInt(diaAudioConfig, CFG_SFX_VOLUME, gSFXVolume);
diaSetInt(diaAudioConfig, CFG_BOOT_SND_VOLUME, gBootSndVolume);
diaSetInt(diaAudioConfig, CFG_BGM_VOLUME, gBGMVolume);
diaSetString(diaAudioConfig, CFG_DEFAULT_BGM_PATH, gDefaultBGMPath);

diaExecuteDialog(diaAudioConfig, -1, 1, guiAudioUpdater);
}
Expand Down Expand Up @@ -1494,6 +1511,9 @@ void guiMainLoop(void)
if (gOPLPart[0] != '\0')
showPartPopup = 1;

if (gEnableBGM)
bgmStart();

while (!gTerminate) {
guiStartFrame();

Expand Down
4 changes: 4 additions & 0 deletions src/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "include/fntsys.h"
#include "include/ioman.h"
#include "include/themes.h"
#include "include/sound.h"

static int guiLangID = 0;
static char **lang_strs = internalEnglish;
Expand Down Expand Up @@ -192,11 +193,13 @@ int lngSetGuiValue(int langID)
{
if (langID != -1) {
if (guiLangID != langID) {
bgmMute();
if (langID != 0) {
language_t *currLang = &languages[langID - 1];
if (lngLoadFromFile(currLang->filePath, currLang->name)) {
guiLangID = langID;
thmSetGuiValue(thmGetGuiValue(), 1);
bgmUnMute();
return 1;
}
}
Expand All @@ -205,6 +208,7 @@ int lngSetGuiValue(int langID)
// lang switched back to internalEnglish, reload default font
fntLoadDefault(NULL);
thmSetGuiValue(thmGetGuiValue(), 1);
bgmUnMute();
}
}
return 0;
Expand Down
26 changes: 22 additions & 4 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ int gSelectButton;
int gHDDGameListCache;
int gEnableSFX;
int gEnableBootSND;
int gEnableBGM;
int gSFXVolume;
int gBootSndVolume;
int gBGMVolume;
char gDefaultBGMPath[128];
int gCheatSource;
int gGSMSource;
int gPadEmuSource;
Expand Down Expand Up @@ -881,8 +884,11 @@ static void _loadConfig()
configGetInt(configOPL, CONFIG_OPL_ENABLE_MX4SIO, &gEnableMX4SIO);
configGetInt(configOPL, CONFIG_OPL_SFX, &gEnableSFX);
configGetInt(configOPL, CONFIG_OPL_BOOT_SND, &gEnableBootSND);
configGetInt(configOPL, CONFIG_OPL_BGM, &gEnableBGM);
configGetInt(configOPL, CONFIG_OPL_SFX_VOLUME, &gSFXVolume);
configGetInt(configOPL, CONFIG_OPL_BOOT_SND_VOLUME, &gBootSndVolume);
configGetInt(configOPL, CONFIG_OPL_BGM_VOLUME, &gBGMVolume);
configGetStrCopy(configOPL, CONFIG_OPL_DEFAULT_BGM_PATH, gDefaultBGMPath, sizeof(gDefaultBGMPath));
}
}

Expand Down Expand Up @@ -1037,8 +1043,11 @@ static void _saveConfig()
configSetInt(configOPL, CONFIG_OPL_ENABLE_MX4SIO, gEnableMX4SIO);
configSetInt(configOPL, CONFIG_OPL_SFX, gEnableSFX);
configSetInt(configOPL, CONFIG_OPL_BOOT_SND, gEnableBootSND);
configSetInt(configOPL, CONFIG_OPL_BGM, gEnableBGM);
configSetInt(configOPL, CONFIG_OPL_SFX_VOLUME, gSFXVolume);
configSetInt(configOPL, CONFIG_OPL_BOOT_SND_VOLUME, gBootSndVolume);
configSetInt(configOPL, CONFIG_OPL_BGM_VOLUME, gBGMVolume);
configSetStr(configOPL, CONFIG_OPL_DEFAULT_BGM_PATH, gDefaultBGMPath);

configSetInt(configOPL, CONFIG_OPL_SWAP_SEL_BUTTON, gSelectButton == KEY_CIRCLE ? 0 : 1);
}
Expand Down Expand Up @@ -1090,6 +1099,7 @@ void applyConfig(int themeID, int langID)

int changed = rmSetMode(0);
if (changed) {
bgmMute();
// reinit the graphics...
thmReloadScreenExtents();
guiReloadScreenExtents();
Expand All @@ -1108,6 +1118,8 @@ void applyConfig(int themeID, int langID)
moduleUpdateMenu(HDD_MODE, changed, langChanged);
moduleUpdateMenu(APP_MODE, changed, langChanged);

bgmUnMute();

#ifdef __DEBUG
debugApplyConfig();
#endif
Expand Down Expand Up @@ -1407,7 +1419,7 @@ static int loadLwnbdSvr(void)
int ret, padStatus;

// deint audio lib while nbd server is running
sfxEnd();
audioEnd();

// block all io ops, wait for the ones still running to finish
ioBlockOps(1);
Expand Down Expand Up @@ -1466,8 +1478,10 @@ static void unloadLwnbdSvr(void)
// init all supports again
initAllSupport(1);

// deferred reinit of audio lib to avoid crashing if devices aren't ready
ioPutRequest(IO_CUSTOM_SIMPLEACTION, &deferredAudioInit);
audioInit();
sfxInit(0);
if (gEnableBGM)
bgmStart();
}

void handleLwnbdSrv()
Expand Down Expand Up @@ -1528,7 +1542,7 @@ void deinit(int exception, int modeSelected)

deinitAllSupport(exception, modeSelected);

sfxEnd();
audioEnd();
ioEnd();
guiEnd();
menuEnd();
Expand Down Expand Up @@ -1622,8 +1636,11 @@ static void setDefaults(void)
gWideScreen = 0;
gEnableSFX = 0;
gEnableBootSND = 0;
gEnableBGM = 0;
gSFXVolume = 80;
gBootSndVolume = 80;
gBGMVolume = 70;
gDefaultBGMPath[0] = '\0';

gBDMStartMode = START_MODE_DISABLED;
gHDDStartMode = START_MODE_DISABLED;
Expand Down Expand Up @@ -1700,6 +1717,7 @@ static void deferredAudioInit(void)
{
int ret;

audioInit();
ret = sfxInit(1);
if (ret < 0)
LOG("sfxInit: failed to initialize - %d.\n", ret);
Expand Down