audiosystem base level done along with its components
This commit is contained in:
parent
c4105510b8
commit
d7b5ae9f02
|
@ -33,7 +33,8 @@ project "SHADE_Application"
|
||||||
"%{IncludeDir.spdlog}/include",
|
"%{IncludeDir.spdlog}/include",
|
||||||
"%{IncludeDir.VULKAN}/include",
|
"%{IncludeDir.VULKAN}/include",
|
||||||
"%{IncludeDir.VMA}/include",
|
"%{IncludeDir.VMA}/include",
|
||||||
"%{IncludeDir.VULKAN}/Source/SPIRV-Reflect"
|
"%{IncludeDir.VULKAN}/Source/SPIRV-Reflect",
|
||||||
|
"%{IncludeDir.fmod}/include"
|
||||||
}
|
}
|
||||||
|
|
||||||
externalwarnings "Off"
|
externalwarnings "Off"
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
#include "Math/Transform/SHTransformSystem.h"
|
#include "Math/Transform/SHTransformSystem.h"
|
||||||
|
#include "AudioSystem/SHAudioSystem.h"
|
||||||
|
#include "AudioSystem/SHAudioSourceComponent.h"
|
||||||
|
#include "AudioSystem/SHAudioListenerComponent.h"
|
||||||
|
|
||||||
#include "Scenes/SBTestScene.h"
|
#include "Scenes/SBTestScene.h"
|
||||||
|
|
||||||
|
@ -51,6 +54,7 @@ namespace Sandbox
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHTransformSystem>();
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHTransformSystem>();
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
||||||
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
||||||
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHAudioSystem>();
|
||||||
|
|
||||||
// Create Routines
|
// Create Routines
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::FrameSetUpRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::FrameSetUpRoutine>();
|
||||||
|
@ -69,6 +73,10 @@ namespace Sandbox
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::EndRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::EndRoutine>();
|
||||||
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHRenderable>();
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHRenderable>();
|
||||||
|
|
||||||
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
||||||
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHAudioSourceComponent>();
|
||||||
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHAudioListenerComponent>();
|
||||||
|
|
||||||
// Set up graphics system and windows
|
// Set up graphics system and windows
|
||||||
graphicsSystem->SetWindow(&window);
|
graphicsSystem->SetWindow(&window);
|
||||||
sdlWindow = SDL_CreateWindowFrom(window.GetHWND());
|
sdlWindow = SDL_CreateWindowFrom(window.GetHWND());
|
||||||
|
|
|
@ -10,46 +10,46 @@
|
||||||
|
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHAudioListenerComponent.h"
|
#include "SHAudioListenerComponent.h"
|
||||||
#include "ECS_Base/System/SHSystemManager.h"
|
//#include "ECS_Base/System/SHSystemManager.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
const SHMathVec3f SHAudioListenerComponent::GetPos() const
|
const SHVec3 SHAudioListenerComponent::GetPos() const
|
||||||
{
|
{
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHMathVec3f SHAudioListenerComponent::GetVel() const
|
const SHVec3 SHAudioListenerComponent::GetVel() const
|
||||||
{
|
{
|
||||||
return vel;
|
return vel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHMathVec3f SHAudioListenerComponent::GetForward() const
|
const SHVec3 SHAudioListenerComponent::GetForward() const
|
||||||
{
|
{
|
||||||
return forward;
|
return forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHMathVec3f SHAudioListenerComponent::GetUp() const
|
const SHVec3 SHAudioListenerComponent::GetUp() const
|
||||||
{
|
{
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioListenerComponent::SetPos(SHMathVec3f p)
|
void SHAudioListenerComponent::SetPos(SHVec3 p)
|
||||||
{
|
{
|
||||||
pos = p;
|
pos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioListenerComponent::SetVel(SHMathVec3f v)
|
void SHAudioListenerComponent::SetVel(SHVec3 v)
|
||||||
{
|
{
|
||||||
vel = v;
|
vel = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioListenerComponent::SetForward(SHMathVec3f f)
|
void SHAudioListenerComponent::SetForward(SHVec3 f)
|
||||||
{
|
{
|
||||||
forward = f;
|
forward = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioListenerComponent::SetUp(SHMathVec3f u)
|
void SHAudioListenerComponent::SetUp(SHVec3 u)
|
||||||
{
|
{
|
||||||
up = u;
|
up = u;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "ECS_Base/Components/SHComponent.h"
|
#include "ECS_Base/Components/SHComponent.h"
|
||||||
#include "Math/SHMathVec.h"
|
#include "Math/SHMath.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -23,20 +23,20 @@ namespace SHADE
|
||||||
SHAudioListenerComponent() = default;
|
SHAudioListenerComponent() = default;
|
||||||
~SHAudioListenerComponent() = default;
|
~SHAudioListenerComponent() = default;
|
||||||
|
|
||||||
const SHMathVec3f GetPos() const;
|
const SHVec3 GetPos() const;
|
||||||
const SHMathVec3f GetVel() const;
|
const SHVec3 GetVel() const;
|
||||||
const SHMathVec3f GetForward() const;
|
const SHVec3 GetForward() const;
|
||||||
const SHMathVec3f GetUp() const;
|
const SHVec3 GetUp() const;
|
||||||
|
|
||||||
void SetPos(SHMathVec3f p);
|
void SetPos(SHVec3 p);
|
||||||
void SetVel(SHMathVec3f v);
|
void SetVel(SHVec3 v);
|
||||||
void SetForward(SHMathVec3f f);
|
void SetForward(SHVec3 f);
|
||||||
void SetUp(SHMathVec3f u);
|
void SetUp(SHVec3 u);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SHMathVec3f pos{}, vel{}, forward{}, up{ 0.f,1.f,0.f };
|
SHVec3 pos{}, vel{}, forward{}, up{ 0.f,1.f,0.f };
|
||||||
};
|
};
|
||||||
}//namespace SHADE
|
}//namespace SHADE
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ namespace SHADE
|
||||||
*
|
*
|
||||||
* @param index where the sound is in the index
|
* @param index where the sound is in the index
|
||||||
*/
|
*/
|
||||||
void SHAudioSourceComponent::PlaySoundSFX(EntityID id, bool loop, bool spatial)
|
void SHAudioSourceComponent::PlaySoundSFX(EntityID id, bool loop, bool spatial, float min , float max )
|
||||||
{
|
{
|
||||||
SHSystemManager::GetSystem<SHAudioSystem>()->PlaySFX(id, GetEID(),loop,spatial);
|
SHSystemManager::GetSystem<SHAudioSystem>()->PlaySFX(id, GetEID(),loop,spatial, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void SHAudioSourceComponent::PlayOneShot(const char* path, bool isSFX, bool spatial)
|
//void SHAudioSourceComponent::PlayOneShot(const char* path, bool isSFX, bool spatial)
|
||||||
|
@ -46,9 +46,9 @@ namespace SHADE
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void SHAudioSourceComponent::PlaySoundBGM(EntityID id, bool loop, bool spatial)
|
void SHAudioSourceComponent::PlaySoundBGM(EntityID id, bool loop, bool spatial, float min, float max)
|
||||||
{
|
{
|
||||||
SHSystemManager::GetSystem<SHAudioSystem>()->PlayBGM(id, GetEID(), loop, spatial);
|
SHSystemManager::GetSystem<SHAudioSystem>()->PlayBGM(id, GetEID(), loop, spatial, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,9 +35,9 @@ namespace SHADE
|
||||||
*
|
*
|
||||||
* @param index where the sound is in the index
|
* @param index where the sound is in the index
|
||||||
*/
|
*/
|
||||||
void PlaySoundSFX(EntityID id, bool loop = false, bool spatial = false);
|
void PlaySoundSFX(EntityID id, bool loop = false, bool spatial = false, float min = 5.0f, float max = 1000.f);
|
||||||
|
|
||||||
void PlaySoundBGM(EntityID id, bool loop = false, bool spatial = false);
|
void PlaySoundBGM(EntityID id, bool loop = false, bool spatial = false, float min = 5.0f, float max = 1000.f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stop the sound
|
* @brief Stop the sound
|
||||||
|
|
|
@ -3,27 +3,25 @@
|
||||||
#include "SHAudioSystem.h"
|
#include "SHAudioSystem.h"
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//#include "Components/SHAudioListenerComponent.h"
|
#include "AudioSystem/SHAudioListenerComponent.h"
|
||||||
//#include "Components/SHAudioSourceComponent.h"
|
#include "AudioSystem/SHAudioSourceComponent.h"
|
||||||
//#include "ECS_Base/System/SHComponentManager.h"
|
//#include "ECS_Base/System/SHComponentManager.h"
|
||||||
//#include "Resource Manager/SHResourceManager.h"
|
//#include "Resource Manager/SHResourceManager.h"
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:26812) //disable warning about preference of enum class over enum as ImGuizmo uses enums
|
#pragma warning(disable:26812) //disable warning about preference of enum class over enum as ImGuizmo uses enums
|
||||||
//#include "fmod_errors.h"
|
|
||||||
//#include "fmod.hpp"
|
|
||||||
//#include "fmod_studio.hpp"
|
|
||||||
#include <FMOD/fmod_errors.h>
|
#include <FMOD/fmod_errors.h>
|
||||||
#include <FMOD/fmod.hpp>
|
#include <FMOD/fmod.hpp>
|
||||||
#include <FMOD/fmod_studio.hpp>
|
#include <FMOD/fmod_studio.hpp>
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
SHAudioSystem::SHAudioSystem()
|
SHAudioSystem::SHAudioSystem()
|
||||||
: system(nullptr)
|
: fmodStudioSystem(nullptr)
|
||||||
, extraDriverData(nullptr)
|
, extraDriverData(nullptr)
|
||||||
, soundList()
|
, soundList()
|
||||||
, bgmChannelGroup(nullptr)
|
, bgmChannelGroup(nullptr)
|
||||||
|
@ -38,7 +36,7 @@ namespace SHADE
|
||||||
, speakerMode(FMOD_SPEAKERMODE_5POINT1)
|
, speakerMode(FMOD_SPEAKERMODE_5POINT1)
|
||||||
, paused(false)
|
, paused(false)
|
||||||
{
|
{
|
||||||
result = FMOD::Studio::System::create(&system);
|
result = FMOD::Studio::System::create(&fmodStudioSystem);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +47,11 @@ namespace SHADE
|
||||||
void SHADE::SHAudioSystem::Init()
|
void SHADE::SHAudioSystem::Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
//SHComponentManager::CreateComponentSparseSet<SHAudioSourceComponent>();
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHAudioSourceComponent>();
|
||||||
//SHComponentManager::CreateComponentSparseSet<SHAudioListenerComponent>();
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHAudioListenerComponent>();
|
||||||
|
|
||||||
denseListener = &SHComponentManager::GetDense<SHAudioListenerComponent>();
|
denseListener = &SHComponentManager::GetDense<SHAudioListenerComponent>();
|
||||||
system->getCoreSystem(&coreSystem);
|
fmodStudioSystem->getCoreSystem(&fmodSystem);
|
||||||
//result = coreSystem->getVersion(&version);
|
//result = coreSystem->getVersion(&version);
|
||||||
//ErrorCheck();
|
//ErrorCheck();
|
||||||
//if (version < FMOD_VERSION)
|
//if (version < FMOD_VERSION)
|
||||||
|
@ -62,18 +60,18 @@ namespace SHADE
|
||||||
// std::cerr << "FMOD version mismatch." << std::endl;
|
// std::cerr << "FMOD version mismatch." << std::endl;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
result = system->initialize(AUDIO_SYS_MAX_CHANNELS, AUDIO_SYS_MAX_CHANNELS, FMOD_STUDIO_INIT_NORMAL, extraDriverData);
|
result = fmodStudioSystem->initialize(AUDIO_SYS_MAX_CHANNELS, AUDIO_SYS_MAX_CHANNELS, FMOD_STUDIO_INIT_NORMAL, extraDriverData);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
|
|
||||||
coreSystem->setSoftwareFormat(0, speakerMode, 0);
|
fmodSystem->setSoftwareFormat(0, speakerMode, 0);
|
||||||
|
|
||||||
result = coreSystem->createChannelGroup("SFX", &sfxChannelGroup);
|
result = fmodSystem->createChannelGroup("SFX", &sfxChannelGroup);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
|
|
||||||
result = coreSystem->createChannelGroup("BGM", &bgmChannelGroup);
|
result = fmodSystem->createChannelGroup("BGM", &bgmChannelGroup);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
|
|
||||||
result = coreSystem->getMasterChannelGroup(&masterGroup);
|
result = fmodSystem->getMasterChannelGroup(&masterGroup);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
|
|
||||||
result = masterGroup->addGroup(bgmChannelGroup);
|
result = masterGroup->addGroup(bgmChannelGroup);
|
||||||
|
@ -87,7 +85,7 @@ namespace SHADE
|
||||||
sfxChannelGroup->setVolume(sfxVolume);
|
sfxChannelGroup->setVolume(sfxVolume);
|
||||||
masterGroup->setVolume(masterVolume);
|
masterGroup->setVolume(masterVolume);
|
||||||
|
|
||||||
SHResourceManager::LoadAllAudio(system, soundList);
|
//SHResourceManager::LoadAllAudio(system, soundList);
|
||||||
|
|
||||||
//TODO: Move to SHResourceManager (LoadAllAudio to load all .bank files and store SHBanks in bankMap)
|
//TODO: Move to SHResourceManager (LoadAllAudio to load all .bank files and store SHBanks in bankMap)
|
||||||
//result = system->loadBankFile("resources/audio/banks/Master.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank);
|
//result = system->loadBankFile("resources/audio/banks/Master.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank);
|
||||||
|
@ -110,23 +108,33 @@ namespace SHADE
|
||||||
void SHADE::SHAudioSystem::Run(float dt)
|
void SHADE::SHAudioSystem::Run(float dt)
|
||||||
{
|
{
|
||||||
static_cast<void>(dt);
|
static_cast<void>(dt);
|
||||||
system->update();
|
fmodStudioSystem->update();
|
||||||
if (!denseListener->empty())
|
if (!denseListener->empty())
|
||||||
{
|
{
|
||||||
SHAudioListenerComponent& listener = denseListener->at(0);
|
SHAudioListenerComponent& listener = denseListener->at(0);
|
||||||
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
|
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
|
||||||
listener.SetPos(listenerTransform->GetLocalPosition());
|
if (listenerTransform)
|
||||||
listener.SetForward({ (listenerTransform->GetScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f });
|
{
|
||||||
FMOD_VECTOR pos = { listener.pos[0] ,listener.pos[1] ,0.f };
|
listener.SetPos(listenerTransform->GetLocalPosition());
|
||||||
FMOD_VECTOR forward = { listener.forward[0] ,listener.forward[1] ,listener.forward[2] };
|
listener.SetForward({ (listenerTransform->GetLocalScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f });
|
||||||
FMOD_VECTOR up = { listener.up[0] ,listener.up[1] ,listener.up[2] };
|
FMOD_VECTOR pos = { listener.pos[0] ,listener.pos[1] ,0.f };
|
||||||
coreSystem->set3DListenerAttributes(0, &pos, nullptr, &forward, &up);
|
FMOD_VECTOR forward = { listener.forward[0] ,listener.forward[1] ,listener.forward[2] };
|
||||||
|
FMOD_VECTOR up = { listener.up[0] ,listener.up[1] ,listener.up[2] };
|
||||||
|
fmodSystem->set3DListenerAttributes(0, &pos, nullptr, &forward, &up);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//int channels;
|
//int channels;
|
||||||
//system->getChannelsPlaying(&channels);
|
//system->getChannelsPlaying(&channels);
|
||||||
//std::cout << "ACTIVE CHANNELS: " << channels << std::endl;
|
//std::cout << "ACTIVE CHANNELS: " << channels << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHAudioSystem::AudioRoutine::AudioRoutine()
|
||||||
|
: SHSystemRoutine("Audio Routine", false) {}
|
||||||
|
void SHAudioSystem::AudioRoutine::Execute(double dt) noexcept
|
||||||
|
{
|
||||||
|
reinterpret_cast<SHAudioSystem*>(system)->Run(dt);
|
||||||
|
}
|
||||||
|
|
||||||
void SHADE::SHAudioSystem::Exit()
|
void SHADE::SHAudioSystem::Exit()
|
||||||
{
|
{
|
||||||
for (auto& event : eventMap)
|
for (auto& event : eventMap)
|
||||||
|
@ -161,7 +169,7 @@ namespace SHADE
|
||||||
|
|
||||||
if (system)
|
if (system)
|
||||||
{
|
{
|
||||||
result = system->release();
|
result = fmodStudioSystem->release();
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +217,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::PlaySFX(ResourceID id, EntityID eid, const bool& loop, const bool& spatial, float min = 5.0f, float max = 1000.0f)
|
void SHAudioSystem::PlaySFX(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min, float max)
|
||||||
{
|
{
|
||||||
SHSound sound = soundList[id];
|
SHSound sound = soundList[id];
|
||||||
int index = GetAvailableChannelIndex();
|
int index = GetAvailableChannelIndex();
|
||||||
|
@ -219,7 +227,7 @@ namespace SHADE
|
||||||
mode |= (loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
|
mode |= (loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
|
||||||
mode |= (spatial ? FMOD_3D : FMOD_2D);
|
mode |= (spatial ? FMOD_3D : FMOD_2D);
|
||||||
sound->setMode(mode);
|
sound->setMode(mode);
|
||||||
result = coreSystem->playSound(sound, sfxChannelGroup, false, &audioChannels[index]);
|
result = fmodSystem->playSound(sound, sfxChannelGroup, false, &audioChannels[index]);
|
||||||
if (spatial && SHComponentManager::HasComponent<SHTransformComponent>(eid))
|
if (spatial && SHComponentManager::HasComponent<SHTransformComponent>(eid))
|
||||||
{
|
{
|
||||||
SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
||||||
|
@ -232,7 +240,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::PlayBGM(ResourceID id, EntityID eid, const bool& loop, const bool& spatial, float min = 5.0f, float max = 1000.0f)
|
void SHAudioSystem::PlayBGM(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min, float max)
|
||||||
{
|
{
|
||||||
SHSound sound = soundList[id];
|
SHSound sound = soundList[id];
|
||||||
int index = GetAvailableChannelIndex();
|
int index = GetAvailableChannelIndex();
|
||||||
|
@ -242,7 +250,7 @@ namespace SHADE
|
||||||
mode |= (loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
|
mode |= (loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
|
||||||
mode |= (spatial ? FMOD_3D : FMOD_2D);
|
mode |= (spatial ? FMOD_3D : FMOD_2D);
|
||||||
sound->setMode(mode);
|
sound->setMode(mode);
|
||||||
result = coreSystem->playSound(sound, bgmChannelGroup, false, &audioChannels[index]);
|
result = fmodSystem->playSound(sound, bgmChannelGroup, false, &audioChannels[index]);
|
||||||
if (spatial && SHComponentManager::HasComponent<SHTransformComponent>(eid))
|
if (spatial && SHComponentManager::HasComponent<SHTransformComponent>(eid))
|
||||||
{
|
{
|
||||||
SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid);
|
||||||
|
@ -255,7 +263,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::SetMute(ResourceID id, bool mute)
|
void SHAudioSystem::SetMute(EntityID id, bool mute)
|
||||||
{
|
{
|
||||||
SHSound sound;
|
SHSound sound;
|
||||||
for (auto& channel : audioChannels)
|
for (auto& channel : audioChannels)
|
||||||
|
@ -268,7 +276,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::StopSound(ResourceID id)
|
void SHAudioSystem::StopSound(EntityID id)
|
||||||
{
|
{
|
||||||
SHSound sound;
|
SHSound sound;
|
||||||
for (auto& channel : audioChannels)
|
for (auto& channel : audioChannels)
|
||||||
|
@ -295,7 +303,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
FMOD_GUID guid;
|
FMOD_GUID guid;
|
||||||
FMOD::Studio::EventDescription* event;
|
FMOD::Studio::EventDescription* event;
|
||||||
result = system->getEvent(path, &event);
|
result = fmodStudioSystem->getEvent(path, &event);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
if (result == FMOD_OK)
|
if (result == FMOD_OK)
|
||||||
{
|
{
|
||||||
|
@ -486,7 +494,7 @@ namespace SHADE
|
||||||
if (!instance)
|
if (!instance)
|
||||||
return;
|
return;
|
||||||
instance->start();
|
instance->start();
|
||||||
auto audioSystem = dynamic_cast<SHAudioSystem*>(SHSystemManager::GetSystem("Audio"));
|
auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||||
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,12 +507,12 @@ namespace SHADE
|
||||||
attributes.forward.z = 1.0f;
|
attributes.forward.z = 1.0f;
|
||||||
attributes.up.y = 1.0f;
|
attributes.up.y = 1.0f;
|
||||||
|
|
||||||
SHVec3 listenerPos = dynamic_cast<SHAudioSystem*>(SHSystemManager::GetSystem("Audio"))->GetListenerPosition();
|
auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||||
|
SHVec3 listenerPos = audioSystem->GetListenerPosition();
|
||||||
attributes.position.x = position[0];
|
attributes.position.x = position[0];
|
||||||
attributes.position.y = position[1];
|
attributes.position.y = position[1];
|
||||||
attributes.position.z = listenerPos[2];
|
attributes.position.z = listenerPos[2];
|
||||||
instance->set3DAttributes(&attributes);
|
instance->set3DAttributes(&attributes);
|
||||||
auto audioSystem = dynamic_cast<SHAudioSystem*>(SHSystemManager::GetSystem("Audio"));
|
|
||||||
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <FMOD/fmod_studio.hpp>
|
|
||||||
#include "ECS_Base/System/SHSystem.h"
|
#include "ECS_Base/System/SHSystem.h"
|
||||||
|
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||||
#include "ECS_Base/SHECSMacros.h"
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
#include "Math/SHMath.h"
|
#include "Math/SHMath.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <FMOD/fmod_studio.hpp>
|
||||||
|
#include "SH_API.h"
|
||||||
#define AUDIO_SYS_MAX_CHANNELS 1024
|
#define AUDIO_SYS_MAX_CHANNELS 1024
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -17,7 +19,9 @@ namespace SHADE
|
||||||
typedef FMOD::Studio::Bank* SHBank;
|
typedef FMOD::Studio::Bank* SHBank;
|
||||||
|
|
||||||
class SHAudioListenerComponent;
|
class SHAudioListenerComponent;
|
||||||
|
|
||||||
typedef uint64_t AudioClipID;
|
typedef uint64_t AudioClipID;
|
||||||
|
|
||||||
class AudioClip
|
class AudioClip
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -39,7 +43,7 @@ namespace SHADE
|
||||||
AudioClipID id;
|
AudioClipID id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHAudioSystem : public SHSystem
|
class SH_API SHAudioSystem : public SHSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SHAudioSystem();
|
SHAudioSystem();
|
||||||
|
@ -47,6 +51,12 @@ namespace SHADE
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Run(float dt);
|
void Run(float dt);
|
||||||
|
class SH_API AudioRoutine final : public SHSystemRoutine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AudioRoutine();
|
||||||
|
void Execute(double dt) noexcept override final;
|
||||||
|
};
|
||||||
void Exit();
|
void Exit();
|
||||||
|
|
||||||
int GetAvailableChannelIndex();
|
int GetAvailableChannelIndex();
|
||||||
|
@ -71,12 +81,12 @@ namespace SHADE
|
||||||
void SetPaused(bool pause);
|
void SetPaused(bool pause);
|
||||||
bool GetPaused() const;
|
bool GetPaused() const;
|
||||||
SHVec3 GetListenerPosition();
|
SHVec3 GetListenerPosition();
|
||||||
void LoadBank(const char* path);
|
//void LoadBank(const char* path);
|
||||||
private:
|
private:
|
||||||
|
FMOD::Studio::System* fmodStudioSystem;
|
||||||
|
FMOD::System* fmodSystem;
|
||||||
bool paused;
|
bool paused;
|
||||||
void ErrorCheck() const;
|
void ErrorCheck() const;
|
||||||
FMOD::Studio::System* system;
|
|
||||||
FMOD::System* coreSystem;
|
|
||||||
|
|
||||||
void* extraDriverData;
|
void* extraDriverData;
|
||||||
std::unordered_map<EntityID, SHSound> soundList;
|
std::unordered_map<EntityID, SHSound> soundList;
|
||||||
|
|
Loading…
Reference in New Issue