Fixed 3d audio #401
|
@ -75,12 +75,12 @@ namespace SHADE
|
|||
fmodSystem->setDSPBufferSize(512, 4);
|
||||
fmodSystem->setOutput(FMOD_OUTPUTTYPE_AUTODETECT);
|
||||
}
|
||||
FMOD_OUTPUTTYPE outputType = FMOD_OUTPUTTYPE_WINSONIC;
|
||||
FMOD_OUTPUTTYPE outputType{};
|
||||
fmodSystem->getSoftwareFormat(0, &speakerMode, 0);
|
||||
fmodSystem->getOutput(&outputType);
|
||||
|
||||
FMOD_STUDIO_INITFLAGS studioInitFlags = FMOD_STUDIO_INIT_NORMAL;
|
||||
FMOD_INITFLAGS coreInitFlags = FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_PREFER_DOLBY_DOWNMIX;
|
||||
FMOD_INITFLAGS coreInitFlags = FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED;
|
||||
#ifdef _DEBUG
|
||||
studioInitFlags |= FMOD_STUDIO_INIT_LIVEUPDATE;
|
||||
coreInitFlags |= FMOD_INIT_PROFILE_ENABLE;
|
||||
|
@ -133,6 +133,10 @@ namespace SHADE
|
|||
const ReceiverPtr ON_PAUSE_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_PAUSE_RECEIVER);
|
||||
SHEventManager::SubscribeTo(SH_EDITOR_ON_PAUSE_EVENT, ON_PAUSE_RECEIVER_PTR);
|
||||
|
||||
const std::shared_ptr ON_SCENE_EXIT_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onSceneExit) };
|
||||
const ReceiverPtr ON_SCENE_EXIT_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_SCENE_EXIT_RECEIVER);
|
||||
SHEventManager::SubscribeTo(SH_SCENE_EXIT_POST, ON_SCENE_EXIT_RECEIVER_PTR);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -174,7 +178,9 @@ namespace SHADE
|
|||
FMOD_3D_ATTRIBUTES attribs{ { 0 } };
|
||||
SHVec3 pos = camComponent->GetPosition();
|
||||
SHVec3 forward, up, right;
|
||||
|
||||
camSystem->GetCameraAxis(*camComponent, forward, right, up);
|
||||
up *= -1.0f;
|
||||
attribs.position = { pos.x, pos.y, pos.z };
|
||||
attribs.forward = { forward.x, forward.y, forward.z };
|
||||
attribs.up = { up.x, up.y, up.z };
|
||||
|
@ -185,7 +191,7 @@ namespace SHADE
|
|||
auto [begin, end] = audioClipLibrary.GetDenseAccess();
|
||||
for (auto& it = begin; it != end; ++it)
|
||||
{
|
||||
if(it->instance && (it->transformRef != MAX_EID))
|
||||
if(it->instance && it->instance->isValid() && (it->transformRef != MAX_EID))
|
||||
{
|
||||
if(SHTransformComponent* transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(it->transformRef))
|
||||
{
|
||||
|
@ -194,11 +200,13 @@ namespace SHADE
|
|||
SHQuaternion worldOrientation = transformComponent->GetWorldOrientation();
|
||||
SHVec3 orientatedFoward = (worldOrientation * SHQuaternion::FromEuler(SHVec3::Forward) * SHQuaternion::Conjugate(worldOrientation)).ToEuler();
|
||||
SHVec3 orientatedUp = (worldOrientation * SHQuaternion::FromEuler(SHVec3::Up) * SHQuaternion::Conjugate(worldOrientation)).ToEuler();
|
||||
|
||||
orientatedFoward = SHVec3::Normalise(orientatedFoward);
|
||||
orientatedUp = SHVec3::Normalise(orientatedUp);
|
||||
attribs.position = {pos.x, pos.y, pos.z};
|
||||
attribs.forward = {orientatedFoward.x, orientatedFoward.y, orientatedFoward.z};
|
||||
attribs.up = {orientatedUp.x, orientatedUp.y, orientatedUp.z};
|
||||
it->instance->set3DAttributes(&attribs);
|
||||
result = it->instance->set3DAttributes(&attribs);
|
||||
ErrorCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -825,6 +833,18 @@ namespace SHADE
|
|||
|
||||
return onStopEvent->handle;
|
||||
}
|
||||
|
||||
SHEventHandle SHAudioSystem::onSceneExit(SHEventPtr onSceneExitEvent)
|
||||
{
|
||||
auto [begin, end] = audioClipLibrary.GetDenseAccess();
|
||||
for (auto& it = begin; it != end; ++it)
|
||||
{
|
||||
it->instance->release();
|
||||
}
|
||||
|
||||
return onSceneExitEvent->handle;
|
||||
}
|
||||
|
||||
SHEventHandle SHAudioSystem::onPlay(SHEventPtr onStopEvent)
|
||||
{
|
||||
if(GetPaused())
|
||||
|
|
|
@ -123,6 +123,7 @@ namespace SHADE
|
|||
SHEventHandle onPlay(SHEventPtr onStopEvent);
|
||||
SHEventHandle onStop(SHEventPtr onStopEvent);
|
||||
SHEventHandle onPause(SHEventPtr onStopEvent);
|
||||
SHEventHandle onSceneExit(SHEventPtr onSceneExitEvent);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue