god knows whats diff but audio is sort of working ish

This commit is contained in:
Glence 2022-09-27 23:57:11 +08:00
parent 3c3b6a285b
commit 7fcac5e0eb
8 changed files with 66 additions and 54 deletions

Binary file not shown.

Binary file not shown.

BIN
Assets/Audio/Music.bank Normal file

Binary file not shown.

BIN
Assets/Audio/SFX.bank Normal file

Binary file not shown.

BIN
Assets/Audio/testogg.ogg Normal file

Binary file not shown.

BIN
Assets/Audio/testwave.wav Normal file

Binary file not shown.

View File

@ -79,12 +79,13 @@ namespace SHADE
LoadBank("../../Assets/Audio/Master.bank");
LoadBank("../../Assets/Audio/Master.strings.bank");
//LoadBank("resources/audio/banks/Music.bank");
//LoadBank("resources/audio/banks/SFX.bank");
LoadBank("../../Assets/Audio/Music.bank");
LoadBank("../../Assets/Audio/SFX.bank");
//auto clip = CreateAudioClip("event:/SFX/Dawn/Dawn_Attack");
//auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human");
//clip->Play();
//PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
//PlayEventOnce("event:/Characters/sfx_footsteps_human");
PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
}
void SHADE::SHAudioSystem::Run(float dt)
@ -147,7 +148,7 @@ namespace SHADE
ErrorCheck();
}
if (system)
if (fmodStudioSystem)
{
result = fmodStudioSystem->release();
ErrorCheck();
@ -160,41 +161,41 @@ namespace SHADE
std::cerr << "Audio system error: " << FMOD_ErrorString(result) << std::endl;
}
void SHAudioSystem::PlayEventOnce(const char* path, bool isSFX, EntityID eid, bool spatial)
void SHAudioSystem::PlayEventOnce(const char* path, bool isSFX, EntityID eid, bool spatial)
{
if (paused)
return;
auto it = eventMap.find(path);
if (it != eventMap.end())
{
FMOD::Studio::EventInstance* event = nullptr;
it->second->createInstance(&event);
if (event)
if (paused)
return;
auto it = eventMap.find(path);
if (it != eventMap.end())
{
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
if (spatial)
{
if (SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
FMOD::Studio::EventInstance* event = nullptr;
it->second->createInstance(&event);
if (event)
{
FMOD_3D_ATTRIBUTES attributes{ {} };
attributes.forward.z = 1.0f;
attributes.up.y = 1.0f;
SHAudioListenerComponent& listener = denseListener->at(0);
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
if (listenerTransform)
{
attributes.position.z = listenerTransform->GetLocalPosition()[2];
}
attributes.position.x = audioTransform->GetLocalPosition()[0];
attributes.position.y = audioTransform->GetLocalPosition()[1];
event->set3DAttributes(&attributes);
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
if (spatial)
{
if (SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
{
FMOD_3D_ATTRIBUTES attributes{ {} };
attributes.forward.z = 1.0f;
attributes.up.y = 1.0f;
SHAudioListenerComponent& listener = denseListener->at(0);
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
if (listenerTransform)
{
attributes.position.z = listenerTransform->GetLocalPosition()[2];
}
attributes.position.x = audioTransform->GetLocalPosition()[0];
attributes.position.y = audioTransform->GetLocalPosition()[1];
event->set3DAttributes(&attributes);
}
}
event->start();
event->release();
}
}
event->start();
event->release();
}
}
}
void SHAudioSystem::PlaySFX(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min, float max)
@ -437,27 +438,27 @@ namespace SHADE
void SHAudioSystem::LoadBank(const char* path)
{
FMOD::Studio::Bank* bank = nullptr;
result = fmodStudioSystem->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank);
ErrorCheck();
if (result != FMOD_OK)
return;
bankMap.emplace(path, bank);
bank->loadSampleData();
int numOfEvents;
bank->getEventCount(&numOfEvents);
if (numOfEvents > 0)
{
std::vector<FMOD::Studio::EventDescription*> events(numOfEvents);
bank->getEventList(events.data(), numOfEvents, &numOfEvents);
char eventName[512];
for (int i{}; i < numOfEvents; ++i)
FMOD::Studio::Bank* bank = nullptr;
result = fmodStudioSystem->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank);
ErrorCheck();
if (result != FMOD_OK)
return;
bankMap.emplace(path, bank);
bank->loadSampleData();
int numOfEvents;
bank->getEventCount(&numOfEvents);
if (numOfEvents > 0)
{
FMOD::Studio::EventDescription* event = events[i];
event->getPath(eventName, 512, nullptr);
eventMap.emplace(eventName, event);
std::vector<FMOD::Studio::EventDescription*> events(numOfEvents);
bank->getEventList(events.data(), numOfEvents, &numOfEvents);
char eventName[512];
for (int i{}; i < numOfEvents; ++i)
{
FMOD::Studio::EventDescription* event = events[i];
event->getPath(eventName, 512, nullptr);
eventMap.emplace(eventName, event);
}
}
}
}
AudioClip::AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst)

View File

@ -13,6 +13,9 @@
#include "SHEditorComponentView.hpp"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "AudioSystem/SHAudioSystem.h"
namespace SHADE
{
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
@ -50,6 +53,14 @@ namespace SHADE
ImGui::InputText("##EntityName", &entity->name);
if (ImGui::Button("AUDIO"))
{
if (auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>())
{
audioSystem->PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
}
}
if (auto transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
{
DrawComponent(transformComponent);