diff --git a/sound/fmod/fmod.c b/sound/fmod/fmod.c new file mode 100644 index 000000000..54bf974aa --- /dev/null +++ b/sound/fmod/fmod.c @@ -0,0 +1,99 @@ +/* Copyright (c) Taylor Daley, 2023. */ +/* fmod.c */ +/* NetHack may be freely redistributed. See license for details. */ + +#ifdef SND_LIB_FMOD + +#include "hack.h" +#include "fmod.h" + +static FMOD_SYSTEM *systemvar; +static FMOD_SOUND *soundvar; +static FMOD_CHANNEL *channel1; +static FMOD_CHANNEL *channelMus; + +static void fmod_init_nhsound(void); +static void fmod_exit_nhsound(const char *); +static void fmod_achievement(schar, schar, int32_t); +static void fmod_soundeffect(char *, int32_t, int32_t); +static void fmod_hero_playnotes(int32_t, const char *, int32_t); +static void fmod_play_usersound(const char *, int32_t, int32_t); +static void fmod_ambience(int32_t, int32_t, int32_t); +static void fmod_verbal(char *, int32_t, int32_t, int32_t, int32_t); + +struct sound_procs fmod_procs = { + SOUNDID(fmod), + SOUND_TRIGGER_USERSOUNDS | 0, + fmod_init_nhsound, + fmod_exit_nhsound, + fmod_achievement, + fmod_soundeffect, + fmod_hero_playnotes, + fmod_play_usersound, + fmod_ambience, + fmod_verbal +}; + +static void +fmod_init_nhsound(void) +{ + /* Initialize external sound library */ + FMOD_System_Create(&systemvar, FMOD_VERSION); + FMOD_System_Init(systemvar, 32, FMOD_INIT_NORMAL, 0); +} + +static void +fmod_exit_nhsound(const char *reason) +{ + /* Close / Terminate external sound library */ + FMOD_System_Close(&systemvar); + FMOD_System_Release(&systemvar); +} + +/* fulfill SNDCAP_ACHIEVEMENTS */ +static void +fmod_achievement(schar ach1, schar ach2, int32_t repeat) +{ + // to be added in future +} + +/* fulfill SNDCAP_SOUNDEFFECTS */ +static void +fmod_soundeffect(char *desc, int32_t seid, int32_t volume) +{ + // to be added in future +} + +/* fulfill SNDCAP_HEROMUSIC */ +static void fmod_hero_playnotes(int32_t instrument, char *str, int32_t volume) +{ + // to be added in future +} + +/* fulfill SOUND_TRIGGER_USERSOUNDS */ +static void +fmod_play_usersound(const char *filename, int32_t volume UNUSED, int32_t idx UNUSED) +{ + FMOD_System_CreateSound(systemvar, filename, FMOD_CREATESAMPLE, 0, + &soundvar); + if (strstr(filename, "music_") != NULL) { + FMOD_Channel_Stop(channelMus); + FMOD_System_PlaySound(systemvar, soundvar, 0, 0, &channelMus); + FMOD_Channel_SetMode(channelMus, FMOD_LOOP_NORMAL); + } else { + FMOD_Channel_Stop(channel1); + FMOD_System_PlaySound(systemvar, soundvar, 0, 0, &channel1); + } +} + +static void +fmod_ambience(int32_t ambienceid, int32_t ambience_action, + int32_t hero_proximity) +{ + // to be added in future +} + + + +#endif /* SND_LIB_FMOD */ + /* end of fmod.c */ \ No newline at end of file diff --git a/sys/windows/windmain.c b/sys/windows/windmain.c index d1d41a516..44bb3bd47 100644 --- a/sys/windows/windmain.c +++ b/sys/windows/windmain.c @@ -592,8 +592,9 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ windowtype = gc.chosen_windowtype; } choose_windows(windowtype); - -#if defined(SND_LIB_WINDSOUND) +#if defined(SND_LIB_FMOD) + assign_soundlib(soundlib_fmod); +#elif defined(SND_LIB_WINDSOUND) assign_soundlib(soundlib_windsound); #endif