85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "IAudioBackend.h"
|
|
#include "AudioConfig.h"
|
|
#include "AudioTypes.h"
|
|
#include <XCEngine/Math/Vector3.h>
|
|
#include <XCEngine/Math/Quaternion.h>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
namespace XCEngine {
|
|
namespace Components {
|
|
class AudioSourceComponent;
|
|
}
|
|
|
|
namespace Audio {
|
|
|
|
class AudioSystem {
|
|
public:
|
|
static AudioSystem& Get();
|
|
|
|
void Initialize(const AudioConfig& config);
|
|
void Shutdown();
|
|
|
|
void Update(float deltaTime);
|
|
|
|
void SetBackend(std::unique_ptr<IAudioBackend> backend);
|
|
IAudioBackend* GetBackend() const { return m_backend.get(); }
|
|
|
|
std::string GetCurrentDevice() const;
|
|
void SetDevice(const std::string& deviceName);
|
|
void GetAvailableDevices(std::vector<std::string>& devices);
|
|
|
|
float GetMasterVolume() const;
|
|
void SetMasterVolume(float volume);
|
|
|
|
bool IsMuted() const;
|
|
void SetMuted(bool muted);
|
|
|
|
void ProcessAudio(float* buffer, uint32 sampleCount, uint32 channels);
|
|
|
|
void SetListenerTransform(const Math::Vector3& position, const Math::Quaternion& rotation);
|
|
void SetListenerVelocity(const Math::Vector3& velocity);
|
|
|
|
const Math::Vector3& GetListenerPosition() const { return m_listenerPosition; }
|
|
const Math::Quaternion& GetListenerRotation() const { return m_listenerRotation; }
|
|
const Math::Vector3& GetListenerVelocity() const { return m_listenerVelocity; }
|
|
|
|
void RegisterSource(Components::AudioSourceComponent* source);
|
|
void UnregisterSource(Components::AudioSourceComponent* source);
|
|
|
|
struct Stats {
|
|
uint32_t activeSources;
|
|
uint32_t totalSources;
|
|
uint64_t memoryUsage;
|
|
float cpuUsage;
|
|
};
|
|
const Stats& GetStats() const { return m_stats; }
|
|
|
|
private:
|
|
AudioSystem() = default;
|
|
~AudioSystem() = default;
|
|
|
|
AudioSystem(const AudioSystem&) = delete;
|
|
AudioSystem& operator=(const AudioSystem&) = delete;
|
|
|
|
void ProcessSource(Components::AudioSourceComponent* source, float* buffer, uint32 sampleCount, uint32 channels);
|
|
|
|
private:
|
|
std::unique_ptr<IAudioBackend> m_backend;
|
|
|
|
Math::Vector3 m_listenerPosition = Math::Vector3::Zero();
|
|
Math::Quaternion m_listenerRotation = Math::Quaternion::Identity();
|
|
Math::Vector3 m_listenerVelocity = Math::Vector3::Zero();
|
|
|
|
std::vector<Components::AudioSourceComponent*> m_activeSources;
|
|
|
|
Stats m_stats = {};
|
|
float m_deltaTime = 0.0f;
|
|
};
|
|
|
|
} // namespace Audio
|
|
} // namespace XCEngine
|