| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // ----------------------------------------------------------------
- // 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 <unordered_map>
- #include <string>
- #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<std::string, FMOD::Studio::Bank*> mBanks;
- // Map of event name to EventDescription
- std::unordered_map<std::string, FMOD::Studio::EventDescription*> mEvents;
- // Map of event id to EventInstance
- std::unordered_map<unsigned int, FMOD::Studio::EventInstance*> mEventInstances;
- // Map of buses
- std::unordered_map<std::string, FMOD::Studio::Bus*> mBuses;
- // FMOD studio system
- FMOD::Studio::System* mSystem;
- // FMOD Low-level system (in case needed)
- FMOD::System* mLowLevelSystem;
- };
|