#include "muxer.h" #include #include void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) { if (result != FMOD_OK) { std::cout << file << "(" << line << "): FMOD error " << result << " - " << FMOD_ErrorString(result); abort(); } } #define ERRCHECK(_result) ERRCHECK_fn(_result, __FILE__, __LINE__) Muxer::Muxer() { FMOD::Studio::System* system_holder = nullptr; ERRCHECK(FMOD::Studio::System::create(&system_holder)); system_.reset(system_holder); FMOD::System* coreSystem = nullptr; ERRCHECK(system_->getCoreSystem(&coreSystem)); ERRCHECK(coreSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_5POINT1, 0)); ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr)); FMOD::Studio::Bank* masterBank = nullptr; ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); FMOD::Studio::Bank* stringsBank = nullptr; ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); FMOD::Studio::EventDescription* exploration_desc = nullptr; ERRCHECK(system_->getEvent("event:/exploration", &exploration_desc)); ERRCHECK(exploration_desc->createInstance(&exploration_event_)); ERRCHECK(exploration_event_->start()); } void Muxer::setPlayerLoc(int x, int y) { FMOD_3D_ATTRIBUTES attributes = {{0}}; attributes.forward.z = 1.0f; attributes.up.y = 1.0f; attributes.position.x = x; attributes.position.y = y; ERRCHECK(system_->setListenerAttributes(0, &attributes)); } void Muxer::playSoundAtPosition(std::string name, float x, float y) { std::string eventPath = std::string("event:/") + name; FMOD::Studio::EventDescription* eventDescription = nullptr; ERRCHECK(system_->getEvent(eventPath.c_str(), &eventDescription)); FMOD::Studio::EventInstance* eventInstance = nullptr; ERRCHECK(eventDescription->createInstance(&eventInstance)); FMOD_3D_ATTRIBUTES attributes = {{0}}; attributes.forward.z = 1.0f; attributes.up.y = 1.0f; attributes.position.x = x; attributes.position.y = y; ERRCHECK(eventInstance->set3DAttributes(&attributes)); ERRCHECK(eventInstance->start()); ERRCHECK(eventInstance->release()); } void Muxer::setMusicLevel(int level) { ERRCHECK(exploration_event_->setParameterByName("level", level)); } void Muxer::update() { ERRCHECK(system_->update()); }