Sound engine update
This commit is contained in:
@@ -129,7 +129,7 @@ const std::string& MaSoundInstance::GetIdentity() const
|
|||||||
return m_Identity;
|
return m_Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaSoundInstance::Config3D(bool toggle, float minDist, float maxDist, float rolloff)
|
void MaSoundInstance::Config3D(bool toggle, float minDist, float maxDist)
|
||||||
{
|
{
|
||||||
ma_sound_set_spatialization_enabled(&m_Sound, toggle);
|
ma_sound_set_spatialization_enabled(&m_Sound, toggle);
|
||||||
ma_sound_set_rolloff(&m_Sound, 1.0f);
|
ma_sound_set_rolloff(&m_Sound, 1.0f);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
const std::string& GetIdentity() const;
|
const std::string& GetIdentity() const;
|
||||||
|
|
||||||
void Config3D(bool toggle, float minDist = 100.0f/*1m*/, float maxDist = 4000.0f/*40m*/, float rolloff = 1.0f);
|
void Config3D(bool toggle, float minDist = 100.0f/*1m*/, float maxDist = 4000.0f/*40m*/);
|
||||||
|
|
||||||
void Fade(float toVolume, float secDurationFromMinMax);
|
void Fade(float toVolume, float secDurationFromMinMax);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ bool SoundEngine::Initialize()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetListenerPosition(0.0f, 0.0f, 0.0f);
|
ma_engine_listener_set_position(&m_Engine, 0, 0, 0, 0); // engine
|
||||||
|
SetListenerPosition(0.0f, 0.0f, 0.0f); // character
|
||||||
SetListenerOrientation(0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
|
SetListenerOrientation(0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,10 +58,12 @@ MaSoundInstance* SoundEngine::PlaySound3D(const std::string& name, float fx, flo
|
|||||||
if (auto instance = Internal_GetInstance3D(name))
|
if (auto instance = Internal_GetInstance3D(name))
|
||||||
{
|
{
|
||||||
constexpr float minDist = 100.0f; // 1m
|
constexpr float minDist = 100.0f; // 1m
|
||||||
constexpr float maxDist = 4000.0f; // 40m
|
constexpr float maxDist = 5000.0f; // 50m
|
||||||
|
|
||||||
instance->SetPosition(fx, fy, fz);
|
instance->SetPosition(fx - m_CharacterPosition.x,
|
||||||
instance->Config3D(true, minDist, maxDist, 1.0f);
|
fy - m_CharacterPosition.y,
|
||||||
|
fz - m_CharacterPosition.z);
|
||||||
|
instance->Config3D(true, minDist, maxDist);
|
||||||
instance->SetVolume(m_SoundVolume);
|
instance->SetVolume(m_SoundVolume);
|
||||||
instance->Play();
|
instance->Play();
|
||||||
return instance;
|
return instance;
|
||||||
@@ -84,7 +87,7 @@ void SoundEngine::StopAllSound3D()
|
|||||||
instance.Stop();
|
instance.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundEngine::UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwcurFrame, const NSound::TSoundInstanceVector* c_pSoundInstanceVector, bool checkFrequency, bool isMain)
|
void SoundEngine::UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwcurFrame, const NSound::TSoundInstanceVector* c_pSoundInstanceVector, bool checkFrequency)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < c_pSoundInstanceVector->size(); ++i)
|
for (uint32_t i = 0; i < c_pSoundInstanceVector->size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -102,18 +105,7 @@ void SoundEngine::UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwc
|
|||||||
lastPlay = CTimer::Instance().GetCurrentSecond();
|
lastPlay = CTimer::Instance().GetCurrentSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMain) // Sounds coming from main instance will always be played in 2d
|
PlaySound3D(c_rSoundInstance.strSoundFileName, fx, fy, fz);
|
||||||
{
|
|
||||||
// float volume = 0.9f + frandom(-0.1f, 0.1f);
|
|
||||||
// instance->SetPitch(pitch); // Should we play around with pitch a bit?
|
|
||||||
PlaySound2D(c_rSoundInstance.strSoundFileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// float volume = 0.9f + frandom(-0.1f, 0.1f);
|
|
||||||
// instance->SetPitch(pitch); // Should we play around with pitch a bit?
|
|
||||||
PlaySound3D(c_rSoundInstance.strSoundFileName, fx, fy, fz);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +165,7 @@ void SoundEngine::SaveVolume(bool isMinimized)
|
|||||||
{
|
{
|
||||||
constexpr float ratePerSecond = 1.0f / CS_CLIENT_FPS;
|
constexpr float ratePerSecond = 1.0f / CS_CLIENT_FPS;
|
||||||
// 1.0 to 0 in 1s if minimized, 3s if just out of focus
|
// 1.0 to 0 in 1s if minimized, 3s if just out of focus
|
||||||
const float durationOnFullVolume = isMinimized ? 1.0 : 3.0f;
|
const float durationOnFullVolume = isMinimized ? 1.0f : 3.0f;
|
||||||
|
|
||||||
float outOfFocusVolume = 0.35f;
|
float outOfFocusVolume = 0.35f;
|
||||||
if (m_MasterVolume <= outOfFocusVolume)
|
if (m_MasterVolume <= outOfFocusVolume)
|
||||||
@@ -199,14 +191,16 @@ void SoundEngine::SetMasterVolume(float volume)
|
|||||||
|
|
||||||
void SoundEngine::SetListenerPosition(float x, float y, float z)
|
void SoundEngine::SetListenerPosition(float x, float y, float z)
|
||||||
{
|
{
|
||||||
ma_engine_listener_set_position(&m_Engine, 0, x, y, z);
|
m_CharacterPosition.x = x;
|
||||||
|
m_CharacterPosition.y = y;
|
||||||
|
m_CharacterPosition.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundEngine::SetListenerOrientation(float forwardX, float forwardY, float forwardZ,
|
void SoundEngine::SetListenerOrientation(float forwardX, float forwardY, float forwardZ,
|
||||||
float upX, float upY, float upZ)
|
float upX, float upY, float upZ)
|
||||||
{
|
{
|
||||||
ma_engine_listener_set_direction(&m_Engine, 0, forwardX, forwardY, forwardZ);
|
ma_engine_listener_set_direction(&m_Engine, 0, forwardX, forwardY, -forwardZ);
|
||||||
ma_engine_listener_set_world_up(&m_Engine, 0, upX, upY, upZ);
|
ma_engine_listener_set_world_up(&m_Engine, 0, upX, -upY, upZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundEngine::SetListenerVelocity(float x, float y, float z)
|
void SoundEngine::SetListenerVelocity(float x, float y, float z)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
|
|
||||||
void StopAllSound3D();
|
void StopAllSound3D();
|
||||||
|
|
||||||
void UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwcurFrame, const NSound::TSoundInstanceVector* c_pSoundInstanceVector, bool checkFrequency = false, bool isMain = false);
|
void UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwcurFrame, const NSound::TSoundInstanceVector* c_pSoundInstanceVector, bool checkFrequency = false);
|
||||||
|
|
||||||
bool FadeInMusic(const std::string& path, float targetVolume = 1.0f, float fadeInDurationSecondsFromMin = 1.5f);
|
bool FadeInMusic(const std::string& path, float targetVolume = 1.0f, float fadeInDurationSecondsFromMin = 1.5f);
|
||||||
|
|
||||||
@@ -78,6 +78,8 @@ private:
|
|||||||
bool Internal_LoadSoundFromPack(const std::string& name);
|
bool Internal_LoadSoundFromPack(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct { float x, y, z; } m_CharacterPosition{};
|
||||||
|
|
||||||
ma_engine m_Engine{};
|
ma_engine m_Engine{};
|
||||||
std::unordered_map<std::string, std::vector<uint8_t>> m_Files;
|
std::unordered_map<std::string, std::vector<uint8_t>> m_Files;
|
||||||
std::unordered_map<std::string, MaSoundInstance> m_Sounds2D;
|
std::unordered_map<std::string, MaSoundInstance> m_Sounds2D;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ void CEffectInstance::UpdateSound()
|
|||||||
m_matGlobal._43,
|
m_matGlobal._43,
|
||||||
m_dwFrame,
|
m_dwFrame,
|
||||||
m_pSoundInstanceVector,
|
m_pSoundInstanceVector,
|
||||||
false, false);
|
false);
|
||||||
// NOTE : 매트릭스에서 위치를 직접 얻어온다 - [levites]
|
// NOTE : 매트릭스에서 위치를 직접 얻어온다 - [levites]
|
||||||
}
|
}
|
||||||
++m_dwFrame;
|
++m_dwFrame;
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ void CActorInstance::SoundEventProcess(BOOL bCheckFrequency)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const NSound::TSoundInstanceVector* c_pkVct_kSndInst = m_pkCurRaceMotionData->GetSoundInstanceVectorPointer();
|
const NSound::TSoundInstanceVector* c_pkVct_kSndInst = m_pkCurRaceMotionData->GetSoundInstanceVectorPointer();
|
||||||
SoundEngine::Instance().UpdateSoundInstance(m_x, m_y, m_z, m_kCurMotNode.dwcurFrame, c_pkVct_kSndInst,
|
SoundEngine::Instance().UpdateSoundInstance(m_x, m_y, m_z, m_kCurMotNode.dwcurFrame, c_pkVct_kSndInst, bCheckFrequency);
|
||||||
bCheckFrequency, m_isMain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CActorInstance::MotionEventProcess(DWORD dwcurFrame, int iIndex, const CRaceMotionData::TMotionEventData * c_pData)
|
void CActorInstance::MotionEventProcess(DWORD dwcurFrame, int iIndex, const CRaceMotionData::TMotionEventData * c_pData)
|
||||||
|
|||||||
Reference in New Issue
Block a user