// ---------------------------------------------------------------- // 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. // ---------------------------------------------------------------- #pragma once #include #include #include "SoundEvent.h" #include "Math.h" // Forward declarations to avoid including FMOD header namespace FMOD { class System; namespace Studio { class Bank; class EventDescription; class EventInstance; class System; class Bus; }; }; class AudioSystem { public: AudioSystem(class Game* game); ~AudioSystem(); bool Initialize(); void Shutdown(); // Load/unload banks void LoadBank(const std::string& name); void UnloadBank(const std::string& name); void UnloadAllBanks(); SoundEvent PlayEvent(const std::string& name); void Update(float deltaTime); // For positional audio void SetListener(const Matrix4& viewMatrix); // Control buses float GetBusVolume(const std::string& name) const; bool GetBusPaused(const std::string& name) const; void SetBusVolume(const std::string& name, float volume); void SetBusPaused(const std::string& name, bool pause); protected: friend class SoundEvent; FMOD::Studio::EventInstance* GetEventInstance(unsigned int id); private: // Tracks the next ID to use for event instances static unsigned int sNextID; class Game* mGame; // Map of loaded banks std::unordered_map mBanks; // Map of event name to EventDescription std::unordered_map mEvents; // Map of event id to EventInstance std::unordered_map mEventInstances; // Map of buses std::unordered_map mBuses; // FMOD studio system FMOD::Studio::System* mSystem; // FMOD Low-level system (in case needed) FMOD::System* mLowLevelSystem; };