diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-11 15:33:28 -0500 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-11 15:33:28 -0500 |
| commit | 6cfc54f019ea793c75c012af9c8249eac936cfac (patch) | |
| tree | f19eed64e9b284136f3b802d4dee71ee24978646 /src/muxer.cpp | |
| parent | 456122f5f0086ed0dbe1b784266b96e9624aa8e1 (diff) | |
| download | ether-6cfc54f019ea793c75c012af9c8249eac936cfac.tar.gz ether-6cfc54f019ea793c75c012af9c8249eac936cfac.tar.bz2 ether-6cfc54f019ea793c75c012af9c8249eac936cfac.zip | |
Added music and lamp popping sound
Diffstat (limited to 'src/muxer.cpp')
| -rw-r--r-- | src/muxer.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
| diff --git a/src/muxer.cpp b/src/muxer.cpp new file mode 100644 index 0000000..5b09ef8 --- /dev/null +++ b/src/muxer.cpp | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #include "muxer.h" | ||
| 2 | #include <iostream> | ||
| 3 | #include <fmod_errors.h> | ||
| 4 | |||
| 5 | void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) { | ||
| 6 | if (result != FMOD_OK) { | ||
| 7 | std::cout << file << "(" << line << "): FMOD error " << result << " - " << FMOD_ErrorString(result); | ||
| 8 | abort(); | ||
| 9 | } | ||
| 10 | } | ||
| 11 | |||
| 12 | #define ERRCHECK(_result) ERRCHECK_fn(_result, __FILE__, __LINE__) | ||
| 13 | |||
| 14 | Muxer::Muxer() { | ||
| 15 | FMOD::Studio::System* system_holder = nullptr; | ||
| 16 | ERRCHECK(FMOD::Studio::System::create(&system_holder)); | ||
| 17 | system_.reset(system_holder); | ||
| 18 | |||
| 19 | FMOD::System* coreSystem = nullptr; | ||
| 20 | ERRCHECK(system_->getCoreSystem(&coreSystem)); | ||
| 21 | ERRCHECK(coreSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_5POINT1, 0)); | ||
| 22 | ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr)); | ||
| 23 | |||
| 24 | FMOD::Studio::Bank* masterBank = nullptr; | ||
| 25 | ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); | ||
| 26 | |||
| 27 | FMOD::Studio::Bank* stringsBank = nullptr; | ||
| 28 | ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); | ||
| 29 | |||
| 30 | FMOD::Studio::EventDescription* exploration_desc = nullptr; | ||
| 31 | ERRCHECK(system_->getEvent("event:/exploration", &exploration_desc)); | ||
| 32 | ERRCHECK(exploration_desc->createInstance(&exploration_event_)); | ||
| 33 | ERRCHECK(exploration_event_->start()); | ||
| 34 | } | ||
| 35 | |||
| 36 | void Muxer::setPlayerLoc(int x, int y) { | ||
| 37 | FMOD_3D_ATTRIBUTES attributes = {{0}}; | ||
| 38 | attributes.forward.z = 1.0f; | ||
| 39 | attributes.up.y = 1.0f; | ||
| 40 | attributes.position.x = x; | ||
| 41 | attributes.position.y = y; | ||
| 42 | ERRCHECK(system_->setListenerAttributes(0, &attributes)); | ||
| 43 | } | ||
| 44 | |||
| 45 | void Muxer::playSoundAtPosition(std::string name, float x, float y) { | ||
| 46 | std::string eventPath = std::string("event:/") + name; | ||
| 47 | |||
| 48 | FMOD::Studio::EventDescription* eventDescription = nullptr; | ||
| 49 | ERRCHECK(system_->getEvent(eventPath.c_str(), &eventDescription)); | ||
| 50 | |||
| 51 | FMOD::Studio::EventInstance* eventInstance = nullptr; | ||
| 52 | ERRCHECK(eventDescription->createInstance(&eventInstance)); | ||
| 53 | |||
| 54 | FMOD_3D_ATTRIBUTES attributes = {{0}}; | ||
| 55 | attributes.forward.z = 1.0f; | ||
| 56 | attributes.up.y = 1.0f; | ||
| 57 | attributes.position.x = x; | ||
| 58 | attributes.position.y = y; | ||
| 59 | ERRCHECK(eventInstance->set3DAttributes(&attributes)); | ||
| 60 | ERRCHECK(eventInstance->start()); | ||
| 61 | ERRCHECK(eventInstance->release()); | ||
| 62 | } | ||
| 63 | |||
| 64 | void Muxer::setMusicLevel(int level) { | ||
| 65 | ERRCHECK(exploration_event_->setParameterByName("level", level)); | ||
| 66 | } | ||
| 67 | |||
| 68 | void Muxer::update() { | ||
| 69 | ERRCHECK(system_->update()); | ||
| 70 | } | ||
