Add support to load external background music

This commit is contained in:
Daryl Borth 2019-01-06 10:28:50 -07:00
parent f490574b9e
commit f4a583a96d
7 changed files with 47 additions and 3 deletions

View File

@ -43,6 +43,8 @@ https://github.com/dborth/fceugx/releases
* Fixed GameCube controllers not working
* Added ability to load external fonts and activated Japanese/Korean
translations. Simply put the ko.ttf or jp.ttf in the app directory
* Added ability to customize background music. Simply put a bg_music.ogg
in the app directory
* Added ability to change preview image source with + button (thanks Zalo!)
[3.4.1 - January 4, 2019]

View File

@ -894,6 +894,35 @@ size_t LoadFont(char * filepath)
fclose(file);
return loadSize;
}
void LoadBgMusic()
{
char filepath[MAXPATHLEN];
sprintf(filepath, "%s/bg_music.ogg", appPath);
FILE *file = fopen (filepath, "rb");
if(!file) {
return;
}
fseeko(file,0,SEEK_END);
size_t ogg_size = ftello(file);
if(ogg_size == 0) {
return;
}
u8 * ogg_data = (u8 *)mem2_malloc(ogg_size);
if(!ogg_data) {
return;
}
fseeko(file, 0, SEEK_SET);
fread (ogg_data, 1, ogg_size, file);
fclose(file);
bg_music = ogg_data;
bg_music_size = ogg_size;
}
#endif
/****************************************************************************

View File

@ -38,6 +38,7 @@ size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize
size_t LoadFile(char * filepath, bool silent);
size_t LoadSzFile(char * filepath, unsigned char * rbuffer);
size_t LoadFont(char *filepath);
void LoadBgMusic();
size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent);
size_t SaveFile(char * filepath, size_t datasize, bool silent);

View File

@ -62,7 +62,6 @@ static GuiImageData * pointer[4];
#define MEM_DEALLOC(A) free(A)
#endif
static GuiTrigger * trigA = NULL;
static GuiTrigger * trig2 = NULL;
@ -91,6 +90,9 @@ static char progressMsg[201];
static int progressDone = 0;
static int progressTotal = 0;
u8 * bg_music;
u32 bg_music_size;
bool GuiLoaded()
{
if(mainWindow)
@ -4185,7 +4187,7 @@ MainMenu (int menu)
#ifndef NO_SOUND
if(firstRun) {
bgMusic = new GuiSound(bg_music_ogg, bg_music_ogg_size, SOUND_OGG);
bgMusic = new GuiSound(bg_music, bg_music_size, SOUND_OGG);
bgMusic->SetVolume(GCSettings.MusicVolume);
bgMusic->SetLoop(true);
enterSound = new GuiSound(enter_ogg, enter_ogg_size, SOUND_OGG);

View File

@ -23,6 +23,9 @@ void CancelAction();
void ShowProgress (const char *msg, int done, int total);
void ChangeLanguage();
extern u8 * bg_music;
extern u32 bg_music_size;
enum
{
MENU_EXIT = -1,

View File

@ -18,6 +18,7 @@
#include <mxml.h>
#include "fceugx.h"
#include "filelist.h"
#include "button_mapping.h"
#include "filebrowser.h"
#include "menu.h"
@ -621,9 +622,14 @@ bool LoadPrefs()
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CheatFolder);
CreateDirectory(dirPath);
}
#ifdef HW_RVL
bg_music = (u8 * )bg_music_ogg;
bg_music_size = bg_music_ogg_size;
LoadBgMusic();
#endif
ChangeLanguage();
return prefFound;
}

View File

@ -14,6 +14,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <utime.h>
#include <gccore.h>
#include "unzip.h"
#include "menu.h"