GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — code/Chapter11/SoundEvent.cpp at master · gameprogcpp/code Expand file tree/ Copy pathSoundEvent.cppMore file actions 178 lines (161 loc) · 3.57 KB / Copy pathSoundEvent.cppFile metadata and controls178 lines (161 loc) · 3.57 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 // ---------------------------------------------------------------- // From Game Programming in C++ by Sanjay Madhav // Copyright (C) 2017 Sanjay Madhav. All rights reserved. // // Released under the BSD License // See LICENSE in root directory for full details. // ---------------------------------------------------------------- #include "SoundEvent.h" #include "AudioSystem.h" #include <fmod_studio.hpp> SoundEvent::SoundEvent(class AudioSystem* system, unsigned int id) :mSystem(system) ,mID(id) { } SoundEvent::SoundEvent() :mSystem(nullptr) ,mID(0) { } bool SoundEvent::IsValid() { return (mSystem && mSystem->GetEventInstance(mID) != nullptr); } void SoundEvent::Restart() { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->start(); } } void SoundEvent::Stop(bool allowFadeOut /* true */) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { FMOD_STUDIO_STOP_MODE mode = allowFadeOut ? FMOD_STUDIO_STOP_ALLOWFADEOUT : FMOD_STUDIO_STOP_IMMEDIATE; event->stop(mode); } } void SoundEvent::SetPaused(bool pause) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->setPaused(pause); } } void SoundEvent::SetVolume(float value) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->setVolume(value); } } void SoundEvent::SetPitch(float value) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->setPitch(value); } } void SoundEvent::SetParameter(const std::string& name, float value) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->setParameterValue(name.c_str(), value); } } bool SoundEvent::GetPaused() const { bool retVal = false; auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->getPaused(&retVal); } return retVal; } float SoundEvent::GetVolume() const { float retVal = 0.0f; auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->getVolume(&retVal); } return retVal; } float SoundEvent::GetPitch() const { float retVal = 0.0f; auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->getPitch(&retVal); } return retVal; } float SoundEvent::GetParameter(const std::string& name) { float retVal = 0.0f; auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { event->getParameterValue(name.c_str(), &retVal); } return retVal; } bool SoundEvent::Is3D() const { bool retVal = false; auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { // Get the event description FMOD::Studio::EventDescription* ed = nullptr; event->getDescription(&ed); if (ed) { ed->is3D(&retVal); } } return retVal; } namespace { FMOD_VECTOR VecToFMOD(const Vector3& in) { // Convert from our coordinates (+x forward, +y right, +z up) // to FMOD (+z forward, +x right, +y up) FMOD_VECTOR v; v.x = in.y; v.y = in.z; v.z = in.x; return v; } } void SoundEvent::Set3DAttributes(const Matrix4& worldTrans) { auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr; if (event) { FMOD_3D_ATTRIBUTES attr; // Set position, forward, up attr.position = VecToFMOD(worldTrans.GetTranslation()); // In world transform, first row is forward attr.forward = VecToFMOD(worldTrans.GetXAxis()); // Third row is up attr.up = VecToFMOD(worldTrans.GetZAxis()); // Set velocity to zero (fix if using Doppler effect) attr.velocity = { 0.0f, 0.0f, 0.0f }; event->set3DAttributes(&attr); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |