mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 19:22:30 +00:00
feat(sound): Small script related improvements
* chore(build): rename src/util/Log.* to SysMessage.* * chore(ui): implement SetNonSpaceWrap() for error messages * chore(ui): move Video Script methods into CGVideoOptions class * chore(script): temporary fix GetNumOutputDrivers to eliminate loading errors * feat(sound): add SI2 Log methods * chore(sound): add SI2 CVars * chore(ui): implement Script_PlayGlueMusic * chore(sound): update SI2::Init() * fix: resolve compilation errors in variadic macros SI2_ERR and SI2_LOG --------- Co-authored-by: Tristan Cormier <cormiert2@outlook.com>
This commit is contained in:
parent
8596860120
commit
32cfe08d0b
21 changed files with 366 additions and 73 deletions
|
|
@ -13,4 +13,6 @@ target_link_libraries(sound
|
|||
PRIVATE
|
||||
ui
|
||||
util
|
||||
PUBLIC
|
||||
fmod
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,73 @@
|
|||
#include "sound/SI2.hpp"
|
||||
#include "ui/FrameScript.hpp"
|
||||
#include "console/CVar.hpp"
|
||||
#include <storm/Memory.hpp>
|
||||
|
||||
FMOD::System* SI2::sm_pGameSystem = nullptr;
|
||||
FMOD::System* SI2::sm_pChatSystem = nullptr;
|
||||
|
||||
void* F_CALL FMOD_Alloc(unsigned int size, FMOD_MEMORY_TYPE type, const char* sourcestr) {
|
||||
return SMemAlloc(size, sourcestr, 0, 0);
|
||||
}
|
||||
|
||||
void* F_CALL FMOD_ReAlloc(void* ptr, unsigned int size, FMOD_MEMORY_TYPE type, const char* sourcestr) {
|
||||
return SMemReAlloc(ptr, size, sourcestr, 0, 0);
|
||||
}
|
||||
|
||||
void F_CALL FMOD_Free(void* ptr, FMOD_MEMORY_TYPE type, const char* sourcestr) {
|
||||
SMemFree(ptr, sourcestr, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void SI2::RegisterScriptFunctions() {
|
||||
for (int32_t i = 0; i < NUM_SCRIPT_FUNCTIONS_SI2; ++i) {
|
||||
FrameScript_RegisterFunction(
|
||||
SI2::s_ScriptFunctions[i].name,
|
||||
SI2::s_ScriptFunctions[i].method
|
||||
);
|
||||
FrameScript_Method* item = s_ScriptFunctions;
|
||||
while (item->name) {
|
||||
FrameScript_RegisterFunction(item->name, item->method);
|
||||
item++;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SI2::Init(int32_t flag) {
|
||||
|
||||
Log_Init();
|
||||
SI2_LOG("=> Version %s (%s) %s", "1.0.0", "00000", "Feb 25 2024");
|
||||
SI2_LOG(" ");
|
||||
SI2_LOG("=> Setting up Game Sound:");
|
||||
SI2_LOG(" - SESound Engine Init");
|
||||
|
||||
SI2_LOG(" - FMOD Memory Init");
|
||||
FMOD::Memory_Initialize(nullptr, 0, &FMOD_Alloc, &FMOD_ReAlloc, &FMOD_Free);
|
||||
// sub_877440(&off_B1D5E4);
|
||||
|
||||
SI2_LOG(" - FMOD System Create");
|
||||
auto errcode = FMOD::System_Create(&sm_pGameSystem);
|
||||
if (errcode) {
|
||||
if (errcode != FMOD_ERR_DSP_SILENCE && errcode != FMOD_ERR_INVALID_VECTOR && errcode != FMOD_ERR_RECORD) {
|
||||
SI2_ERR(errcode, "");
|
||||
}
|
||||
SI2_LOG(" -###########################################################################################");
|
||||
SI2_ERR(errcode, " -######## ERROR INITIALIZING. ALL GAME SOUND DISABLED.");
|
||||
SI2_LOG(" -###########################################################################################");
|
||||
sm_pGameSystem->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
|
||||
goto LABEL_9;
|
||||
}
|
||||
|
||||
errcode = FMOD::System_Create(&sm_pChatSystem);
|
||||
if (errcode != FMOD_ERR_DSP_SILENCE && errcode != FMOD_ERR_INVALID_VECTOR && errcode != FMOD_ERR_RECORD) {
|
||||
SI2_ERR(errcode, "");
|
||||
}
|
||||
|
||||
if (sm_pChatSystem && sm_pChatSystem->init(4, FMOD_INIT_NORMAL, nullptr)) {
|
||||
sm_pChatSystem->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
|
||||
}
|
||||
|
||||
sm_pGameSystem->setOutput(FMOD_OUTPUTTYPE_AUTODETECT);
|
||||
|
||||
LABEL_9:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SI2::StartGlueMusic(const char* filename) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,34 @@
|
|||
#ifndef SOUND_SI2_HPP
|
||||
#define SOUND_SI2_HPP
|
||||
|
||||
#include "sound/SI2Script.hpp"
|
||||
#include "ui/Types.hpp"
|
||||
#include <storm/Log.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstdarg>
|
||||
#include <fmod.hpp>
|
||||
#include <fmod_errors.h>
|
||||
|
||||
|
||||
#define SI2_ERR(errcode, format, ...) SI2::Log_Write(__LINE__, __FILE__, errcode, format, ##__VA_ARGS__)
|
||||
#define SI2_LOG(format, ...) SI2::Log_Write(__LINE__, __FILE__, FMOD_OK, format, ##__VA_ARGS__)
|
||||
|
||||
class SI2 {
|
||||
public:
|
||||
// Static variables
|
||||
static FrameScript_Method s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2];
|
||||
static FrameScript_Method s_ScriptFunctions[];
|
||||
static uint32_t sm_logFlags;
|
||||
static HSLOG sm_log;
|
||||
static FMOD::System* sm_pGameSystem;
|
||||
static FMOD::System* sm_pChatSystem;
|
||||
|
||||
// Static functions
|
||||
static void RegisterScriptFunctions();
|
||||
static int32_t Log_Init();
|
||||
static void Log_Write(const char* format, ...);
|
||||
static void Log_Write(uint32_t line, const char* filename, FMOD_RESULT errcode, const char* format, ...);
|
||||
static void RegisterCVars();
|
||||
static int32_t Init(int32_t flag);
|
||||
static void StartGlueMusic(const char* filename);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
80
src/sound/SI2Cvars.cpp
Normal file
80
src/sound/SI2Cvars.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include "sound/SI2.hpp"
|
||||
#include "console/CVar.hpp"
|
||||
|
||||
bool OutboundChatVolumeHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InboundChatVolumeHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceChatModeHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceActivationSensitivityHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnableMicrophoneHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnableVoiceChatHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SelfMuteHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PushToTalkButtonHandler(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnableReverb_CVarCallback(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceChatInputDriverIndex_CVarCallback(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VoiceChatOutputDriverIndex_CVarCallback(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OutputDriverIndex_CVarCallback(CVar*, const char*, const char*, void*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SI2::RegisterCVars() {
|
||||
CVar::Register("StartTalkingDelay", "", 0, "0.0", 0, 5, 0, 0, 0);
|
||||
CVar::Register("StartTalkingTime", "", 0, "1.0", 0, 5, 0, 0, 0);
|
||||
CVar::Register("StopTalkingDelay", "", 0, "0.0", 0, 5, 0, 0, 0);
|
||||
CVar::Register("StopTalkingTime", "", 0, "2.0", 0, 5, 0, 0, 0);
|
||||
CVar::Register("OutboundChatVolume", "The software amplification factor (0.0 - 2.0)", 0, "1.0", &OutboundChatVolumeHandler, 5, 0, 0, 0);
|
||||
CVar::Register("InboundChatVolume", "The volume of all other chat you hear (0.0 - 1.0)", 0, "1.0", &InboundChatVolumeHandler, 5, 0, 0, 0);
|
||||
CVar::Register("VoiceChatMode", "Push to talk(0) or voice activation(1)", 0, "0", &VoiceChatModeHandler, 5, 0, 0, 0);
|
||||
CVar::Register("VoiceActivationSensitivity", "Sensitivity of the microphone (0.0 - 1.0)", 0, "0.4", &VoiceActivationSensitivityHandler, 5, 0, 0, 0);
|
||||
CVar::Register("EnableMicrophone", "Enables the microphone so you can speak.", 0, "1", &EnableMicrophoneHandler, 5, 0, 0, 0);
|
||||
CVar::Register("EnableVoiceChat", "Enables the voice chat feature.", 0, "0", &EnableVoiceChatHandler, 5, 0, 0, 0);
|
||||
CVar::Register("VoiceChatSelfMute", "Turn off your ability to talk.", 0, "0", &SelfMuteHandler, 5, 0, 0, 0);
|
||||
CVar::Register("PushToTalkButton", "String representation of the Push-To-Talk button.", 0, "`", &PushToTalkButtonHandler, 5, 0, 0, 0);
|
||||
CVar::Register("Sound_OutputQuality", "sound quality, default 1 (medium)", 0, "1", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_NumChannels", "number of sound channels", 0, "32", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_EnableReverb", "", 0, "0", &EnableReverb_CVarCallback, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_EnableSoftwareHRTF", "", 0, "0", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_VoiceChatInputDriverIndex", "", 0, "0", &VoiceChatInputDriverIndex_CVarCallback, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_VoiceChatInputDriverName", "", 0, "Primary Sound Capture Driver", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_VoiceChatOutputDriverIndex", "", 0, "0", &VoiceChatOutputDriverIndex_CVarCallback, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_VoiceChatOutputDriverName", "", 0, "Primary Sound Driver", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_OutputDriverIndex", "", 0, "0", &OutputDriverIndex_CVarCallback, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_OutputDriverName", "", 0, "Primary Sound Driver", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_DSPBufferSize", "sound buffer size, default 0", 0, "0", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_EnableHardware", "Enables Hardware", 0, "0", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_EnableMode2", "test", 0, "0", 0, 7, 0, 0, 0);
|
||||
CVar::Register("Sound_EnableMixMode2", "test", 0, "0", 0, 7, 0, 0, 0);
|
||||
}
|
||||
71
src/sound/SI2Log.cpp
Normal file
71
src/sound/SI2Log.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#include "sound/SI2.hpp"
|
||||
#include <storm/Error.hpp>
|
||||
#include <bc/os/File.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
uint32_t SI2::sm_logFlags = SLOG_FLAG_DEFAULT;
|
||||
HSLOG SI2::sm_log = nullptr;
|
||||
|
||||
int32_t SI2::Log_Init() {
|
||||
OsCreateDirectory("Logs", 0);
|
||||
SLogCreate("Logs\\Sound.log", sm_logFlags, &sm_log);
|
||||
sm_logFlags |= SLOG_FLAG_APPEND;
|
||||
// return OsDeleteFile((Blizzard::File*)"Logs\\SESound.log");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SI2::Log_Write(const char* format, ...) {
|
||||
STORM_ASSERT(format);
|
||||
|
||||
char output[512] = { 0 };
|
||||
if (format[0]) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vsnprintf(output, sizeof(output), format, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
Log_Write(__LINE__, __FILE__, FMOD_OK, output);
|
||||
}
|
||||
|
||||
void SI2::Log_Write(uint32_t line, const char* filename, FMOD_RESULT errcode, const char* format, ...) {
|
||||
static uint32_t s_nNumErrors = 0;
|
||||
|
||||
if (s_nNumErrors > 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_nNumErrors == 200) {
|
||||
SLogWrite(sm_log, " -######## TOO MANY ERRORS. NO FURTHER ERRORS WILL BE LOGGED.");
|
||||
SLogFlush(sm_log);
|
||||
s_nNumErrors++;
|
||||
return;
|
||||
}
|
||||
|
||||
STORM_ASSERT(format);
|
||||
|
||||
char output[512] = { 0 };
|
||||
if (format[0]) {
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vsnprintf(output, sizeof(output), format, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
if (errcode == FMOD_OK) {
|
||||
SLogWrite(sm_log, output);
|
||||
SLogFlush(sm_log);
|
||||
}
|
||||
|
||||
if (errcode == FMOD_ERR_HTTP_PROXY_AUTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
SLogWrite(sm_log, " -######## FMOD ERROR! (err %d) %s", errcode, FMOD_ErrorString(errcode));
|
||||
if (format[0]) {
|
||||
SLogWrite(sm_log, output);
|
||||
}
|
||||
SLogWrite(sm_log, "%s(%d)", filename, line);
|
||||
SLogFlush(sm_log);
|
||||
s_nNumErrors++;
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
#include "sound/SI2Script.hpp"
|
||||
#include "sound/SI2.hpp"
|
||||
#include "ui/Types.hpp"
|
||||
#include "util/Lua.hpp"
|
||||
|
|
@ -21,7 +20,8 @@ int32_t Script_StopMusic(lua_State* L) {
|
|||
}
|
||||
|
||||
int32_t Script_Sound_GameSystem_GetNumInputDrivers(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
lua_pushnumber(L, 0.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t Script_Sound_GameSystem_GetInputDriverNameByIndex(lua_State* L) {
|
||||
|
|
@ -29,7 +29,10 @@ int32_t Script_Sound_GameSystem_GetInputDriverNameByIndex(lua_State* L) {
|
|||
}
|
||||
|
||||
int32_t Script_Sound_GameSystem_GetNumOutputDrivers(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
// TODO:
|
||||
// NumOutputDrivers = (double)(int)SE3::GetNumOutputDrivers(SE3::sm_pGameSystem, v3);
|
||||
lua_pushnumber(L, 0.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t Script_Sound_GameSystem_GetOutputDriverNameByIndex(lua_State* L) {
|
||||
|
|
@ -96,7 +99,7 @@ int32_t Script_VoiceChat_ActivatePrimaryCaptureCallback(lua_State* L) {
|
|||
WHOA_UNIMPLEMENTED(0);
|
||||
}
|
||||
|
||||
FrameScript_Method SI2::s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2] = {
|
||||
FrameScript_Method SI2::s_ScriptFunctions[] = {
|
||||
{ "PlaySound", &Script_PlaySound },
|
||||
{ "PlayMusic", &Script_PlayMusic },
|
||||
{ "PlaySoundFile", &Script_PlaySoundFile },
|
||||
|
|
@ -119,5 +122,6 @@ FrameScript_Method SI2::s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2] = {
|
|||
{ "VoiceChat_IsRecordingLoopbackSound", &Script_VoiceChat_IsRecordingLoopbackSound },
|
||||
{ "VoiceChat_IsPlayingLoopbackSound", &Script_VoiceChat_IsPlayingLoopbackSound },
|
||||
{ "VoiceChat_GetCurrentMicrophoneSignalLevel", &Script_VoiceChat_GetCurrentMicrophoneSignalLevel },
|
||||
{ "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback }
|
||||
{ "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef SOUND_SI2_SCRIPT_HPP
|
||||
#define SOUND_SI2_SCRIPT_HPP
|
||||
|
||||
#define NUM_SCRIPT_FUNCTIONS_SI2 23
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue