Add more embedded sounds.

This commit is contained in:
Dario 2024-12-12 00:43:44 -03:00
parent 0f17ad23f9
commit b79e92d07a
2 changed files with 37 additions and 12 deletions

View file

@ -402,3 +402,7 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/ga
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon_night.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon_night.bmp" ARRAY_NAME "g_game_icon_night") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon_night.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon_night.bmp" ARRAY_NAME "g_game_icon_night")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_cursor.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_cursor.wav" ARRAY_NAME "g_sys_worldmap_cursor") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_cursor.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_cursor.wav" ARRAY_NAME "g_sys_worldmap_cursor")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_finaldecide.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_finaldecide.wav" ARRAY_NAME "g_sys_worldmap_finaldecide") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_worldmap_finaldecide.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_worldmap_finaldecide.wav" ARRAY_NAME "g_sys_worldmap_finaldecide")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausecursor.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausecursor.wav" ARRAY_NAME "g_sys_actstg_pausecursor")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausedecide.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausedecide.wav" ARRAY_NAME "g_sys_actstg_pausedecide")
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/sounds/sys_actstg_pausewinopen.wav" DEST_FILE "${RESOURCES_OUTPUT_PATH}/sounds/sys_actstg_pausewinopen.wav" ARRAY_NAME "g_sys_actstg_pausewinopen")

View file

@ -5,12 +5,18 @@
#include <res/sounds/sys_worldmap_cursor.wav.h> #include <res/sounds/sys_worldmap_cursor.wav.h>
#include <res/sounds/sys_worldmap_finaldecide.wav.h> #include <res/sounds/sys_worldmap_finaldecide.wav.h>
#include <res/sounds/sys_actstg_pausecursor.wav.h>
#include <res/sounds/sys_actstg_pausedecide.wav.h>
#include <res/sounds/sys_actstg_pausewinopen.wav.h>
enum EmbeddedSound enum class EmbeddedSound
{ {
EmbeddedSoundSysWorldMapCursor, SysWorldMapCursor,
EmbeddedSoundSysWorldMapFinalDecide, SysWorldMapFinalDecide,
EmbeddedSoundCount, SysActStgPauseCursor,
SysActStgPauseDecide,
SysActStgPauseWinOpen,
Count,
}; };
struct EmbeddedSoundData struct EmbeddedSoundData
@ -23,16 +29,19 @@ struct EmbeddedSoundData
static ma_engine g_audioEngine = {}; static ma_engine g_audioEngine = {};
static bool g_audioEngineInitialized = false; static bool g_audioEngineInitialized = false;
static std::array<EmbeddedSoundData, EmbeddedSoundCount> g_embeddedSoundData = {}; static std::array<EmbeddedSoundData, size_t(EmbeddedSound::Count)> g_embeddedSoundData = {};
static const std::unordered_map<std::string, EmbeddedSound> g_embeddedSoundMap = static const std::unordered_map<std::string, EmbeddedSound> g_embeddedSoundMap =
{ {
{ "sys_worldmap_cursor", EmbeddedSoundSysWorldMapCursor }, { "sys_worldmap_cursor", EmbeddedSound::SysWorldMapCursor },
{ "sys_worldmap_finaldecide", EmbeddedSoundSysWorldMapFinalDecide }, { "sys_worldmap_finaldecide", EmbeddedSound::SysWorldMapFinalDecide },
{ "sys_actstg_pausecursor", EmbeddedSound::SysActStgPauseCursor },
{ "sys_actstg_pausedecide", EmbeddedSound::SysActStgPauseDecide },
{ "sys_actstg_pausewinopen", EmbeddedSound::SysActStgPauseWinOpen },
}; };
static void PlayEmbeddedSound(EmbeddedSound s) static void PlayEmbeddedSound(EmbeddedSound s)
{ {
EmbeddedSoundData &data = g_embeddedSoundData[s]; EmbeddedSoundData &data = g_embeddedSoundData[size_t(s)];
int pickedIndex = -1; int pickedIndex = -1;
for (int i = 0; (i < EmbeddedSoundData::SimultaneousLimit) && (pickedIndex < 0); i++) for (int i = 0; (i < EmbeddedSoundData::SimultaneousLimit) && (pickedIndex < 0); i++)
{ {
@ -43,14 +52,26 @@ static void PlayEmbeddedSound(EmbeddedSound s)
size_t soundDataSize = 0; size_t soundDataSize = 0;
switch (s) switch (s)
{ {
case EmbeddedSoundSysWorldMapCursor: case EmbeddedSound::SysWorldMapCursor:
soundData = g_sys_worldmap_cursor; soundData = g_sys_worldmap_cursor;
soundDataSize = sizeof(g_sys_worldmap_cursor); soundDataSize = sizeof(g_sys_worldmap_cursor);
break; break;
case EmbeddedSoundSysWorldMapFinalDecide: case EmbeddedSound::SysWorldMapFinalDecide:
soundData = g_sys_worldmap_finaldecide; soundData = g_sys_worldmap_finaldecide;
soundDataSize = sizeof(g_sys_worldmap_finaldecide); soundDataSize = sizeof(g_sys_worldmap_finaldecide);
break; break;
case EmbeddedSound::SysActStgPauseCursor:
soundData = g_sys_actstg_pausecursor;
soundDataSize = sizeof(g_sys_actstg_pausecursor);
break;
case EmbeddedSound::SysActStgPauseDecide:
soundData = g_sys_actstg_pausedecide;
soundDataSize = sizeof(g_sys_actstg_pausedecide);
break;
case EmbeddedSound::SysActStgPauseWinOpen:
soundData = g_sys_actstg_pausewinopen;
soundDataSize = sizeof(g_sys_actstg_pausewinopen);
break;
default: default:
assert(false && "Unknown embedded sound."); assert(false && "Unknown embedded sound.");
return; return;
@ -61,7 +82,7 @@ static void PlayEmbeddedSound(EmbeddedSound s)
res = ma_decoder_init_memory(soundData, soundDataSize, nullptr, data.decoders[i].get()); res = ma_decoder_init_memory(soundData, soundDataSize, nullptr, data.decoders[i].get());
if (res != MA_SUCCESS) if (res != MA_SUCCESS)
{ {
fprintf(stderr, "ma_decoder_init_memory failed with error code %d on embedded sound %d.\n", res, s); fprintf(stderr, "ma_decoder_init_memory failed with error code %d.\n", res);
return; return;
} }
@ -69,7 +90,7 @@ static void PlayEmbeddedSound(EmbeddedSound s)
res = ma_sound_init_from_data_source(&g_audioEngine, data.decoders[i].get(), MA_SOUND_FLAG_DECODE, nullptr, data.sounds[i].get()); res = ma_sound_init_from_data_source(&g_audioEngine, data.decoders[i].get(), MA_SOUND_FLAG_DECODE, nullptr, data.sounds[i].get());
if (res != MA_SUCCESS) if (res != MA_SUCCESS)
{ {
fprintf(stderr, "ma_sound_init_from_data_source failed with error code %d on embedded sound %d.\n", res, s); fprintf(stderr, "ma_sound_init_from_data_source failed with error code %d.\n", res);
return; return;
} }