Skip to content

Commit

Permalink
Fix gcc warnings and modularize audio system.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf3s committed Jan 5, 2025
1 parent 0d619d2 commit f1570a2
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ifneq ($(GIT_TAG),latest)
endif
endif

FRONTEND_OBJS = pad.o xparam.o fntsys.o renderman.o submenu.o menu.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \
FRONTEND_OBJS = audio.o pad.o xparam.o fntsys.o renderman.o submenu.o menu.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \
dia.o ioman.o texcache.o themes.o supportbase.o bdmsupport.o ethsupport.o hddsupport.o zso.o lz4.o \
appsupport.o gui.o guigame.o textures.o opl.o atlas.o nbns.o httpclient.o gsm.o cheatman.o sound.o ps2cnf.o

Expand Down
8 changes: 8 additions & 0 deletions include/audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __AUDIO_H
#define __AUDIO_H

void audioInit(void);
void audioEnd(void);
void audioSetVolume(int sfx);

#endif
2 changes: 1 addition & 1 deletion include/cheatman.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern cheat_entry_t gCheats[MAX_CODES];

void InitCheatsConfig(config_set_t *configSet);
int GetCheatsEnabled(void);
const u32 *GetCheatsList(void);
u32 *GetCheatsList(void);
int load_cheats(const char *cheatfile);
void set_cheats_list(void);

Expand Down
4 changes: 0 additions & 4 deletions include/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ enum SFX {
SFX_COUNT
};

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

int sfxInit(int bootSnd);
int sfxGetSoundDuration(int id);
void sfxPlay(int id);
Expand Down
40 changes: 40 additions & 0 deletions src/audio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2022-2025, Thanks to SP193 and KrahJohilto
Copyright 2025 André Guilherme(Wofl3s)
Licenced under Academic Free License version 3.0
Review OpenPS2Loader README & LICENSE files for further details.
*/

#include <audsrv.h>

#include "include/audio.h"
#include "include/opl.h"
#include "include/ioman.h"

/*-- General Audio ------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------*/

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

void audioEnd(void)
{
audsrv_quit();
}

void audioSetVolume(int sfx)
{
int i;

for (i = 1; i < sfx; i++)
audsrv_adpcm_set_volume(i, gSFXVolume);

audsrv_adpcm_set_volume(0, gBootSndVolume);
audsrv_set_volume(gBGMVolume);
}
2 changes: 1 addition & 1 deletion src/cheatman.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int GetCheatsEnabled(void)
return gEnableCheat;
}

const u32 *GetCheatsList(void)
u32 *GetCheatsList(void)
{
return gCheatList;
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "include/compatupd.h"
#include "include/pggsm.h"
#include "include/cheatman.h"
#include "include/audio.h"
#include "include/sound.h"
#include "include/guigame.h"

Expand Down Expand Up @@ -882,7 +883,7 @@ static void guiSetAudioSettingsState(void)
diaGetInt(diaAudioConfig, CFG_BOOT_SND_VOLUME, &gBootSndVolume);
diaGetInt(diaAudioConfig, CFG_BGM_VOLUME, &gBGMVolume);
diaGetString(diaAudioConfig, CFG_DEFAULT_BGM_PATH, gDefaultBGMPath, sizeof(gDefaultBGMPath));
audioSetVolume();
audioSetVolume(SFX_COUNT);

if (gEnableBGM && !isBgmPlaying())
bgmStart();
Expand Down
1 change: 1 addition & 0 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "include/appsupport.h"

#include "include/cheatman.h"
#include "include/audio.h"
#include "include/sound.h"
#include "include/xparam.h"

Expand Down
93 changes: 26 additions & 67 deletions src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma GCC diagnostic pop

#include "include/imports.h"
#include "include/audio.h"
#include "include/sound.h"
#include "include/opl.h"
#include "include/ioman.h"
Expand Down Expand Up @@ -38,6 +39,29 @@ static struct sfxEffect sfx_files[SFX_COUNT] = {
static struct audsrv_adpcm_t sfx[SFX_COUNT];
static int audio_initialized = 0;

/*-- Theme Background Music -------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------*/

#define BGM_RING_BUFFER_COUNT 16
#define BGM_RING_BUFFER_SIZE 4096
#define BGM_THREAD_BASE_PRIO 0x40
#define BGM_THREAD_STACK_SIZE 0x1000

extern void *_gp;

static int bgmThreadID, bgmIoThreadID;
static int outSema, inSema;
static unsigned char terminateFlag;
static int bgmIsPlaying;
static unsigned char rdPtr, wrPtr;
static char bgmBuffer[BGM_RING_BUFFER_COUNT][BGM_RING_BUFFER_SIZE];
static volatile unsigned char bgmThreadRunning, bgmIoThreadRunning;

static u8 bgmThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16)));
static u8 bgmIoThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16)));

static OggVorbis_File *vorbisFile;

// Returns 0 if the specified file was read. The sfxEffect structure will not be updated unless the file is successfully read.
static int sfxRead(const char *full_path, struct sfxEffect *sfx)
{
Expand Down Expand Up @@ -148,7 +172,7 @@ int sfxInit(int bootSnd)

audsrv_adpcm_init();
sfxInitDefaults();
audioSetVolume();
audioSetVolume(SFX_COUNT);

// Check default theme is not current theme
int themeID = thmGetGuiValue();
Expand Down Expand Up @@ -211,29 +235,6 @@ void sfxPlay(int id)
}
}

/*-- Theme Background Music -------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------*/

#define BGM_RING_BUFFER_COUNT 16
#define BGM_RING_BUFFER_SIZE 4096
#define BGM_THREAD_BASE_PRIO 0x40
#define BGM_THREAD_STACK_SIZE 0x1000

extern void *_gp;

static int bgmThreadID, bgmIoThreadID;
static int outSema, inSema;
static unsigned char terminateFlag;
static int bgmIsPlaying;
static unsigned char rdPtr, wrPtr;
static char bgmBuffer[BGM_RING_BUFFER_COUNT][BGM_RING_BUFFER_SIZE];
static volatile unsigned char bgmThreadRunning, bgmIoThreadRunning;

static u8 bgmThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16)));
static u8 bgmIoThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16)));

static OggVorbis_File *vorbisFile;

static void bgmThread(void *arg)
{
bgmThreadRunning = 1;
Expand Down Expand Up @@ -495,46 +496,4 @@ void bgmEnd(void)
bgmStop();
}
}
}

/*-- General Audio ------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------*/

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

void audioEnd(void)
{
if (!audio_initialized) {
LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__);
return;
}

audsrv_quit();
audio_initialized = 0;
}

void audioSetVolume(void)
{
int i;

if (!audio_initialized) {
LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__);
return;
}

for (i = 1; i < SFX_COUNT; i++)
audsrv_adpcm_set_volume(i, gSFXVolume);

audsrv_adpcm_set_volume(0, gBootSndVolume);
audsrv_set_volume(gBGMVolume);
}
}
2 changes: 1 addition & 1 deletion src/submenu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2009, Ifcaro & volca
Copyright 2024-2025, André Guilherme
Copyright 2024-2025, André Guilherme(Wolf3s)
Licenced under Academic Free License version 3.0
Review OpenUsbLd README & LICENSE files for further details.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/supportbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ static int scanForISO(char *path, char type, struct game_list_t **glist)

if (MountFD < 0 || GetStartupExecName("iso:/SYSTEM.CNF;1", startup, GAME_STARTUP_MAX - 1) != 0) {
fileXioUmount("iso:");
free(next);
*glist = next->next;
free(next);
next = NULL;
continue;
}

Expand Down

0 comments on commit f1570a2

Please sign in to comment.