Sound engine update
This commit is contained in:
@@ -129,7 +129,7 @@ const std::string& MaSoundInstance::GetIdentity() const
|
||||
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_rolloff(&m_Sound, 1.0f);
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ bool SoundEngine::Initialize()
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@@ -57,10 +58,12 @@ MaSoundInstance* SoundEngine::PlaySound3D(const std::string& name, float fx, flo
|
||||
if (auto instance = Internal_GetInstance3D(name))
|
||||
{
|
||||
constexpr float minDist = 100.0f; // 1m
|
||||
constexpr float maxDist = 4000.0f; // 40m
|
||||
constexpr float maxDist = 5000.0f; // 50m
|
||||
|
||||
instance->SetPosition(fx, fy, fz);
|
||||
instance->Config3D(true, minDist, maxDist, 1.0f);
|
||||
instance->SetPosition(fx - m_CharacterPosition.x,
|
||||
fy - m_CharacterPosition.y,
|
||||
fz - m_CharacterPosition.z);
|
||||
instance->Config3D(true, minDist, maxDist);
|
||||
instance->SetVolume(m_SoundVolume);
|
||||
instance->Play();
|
||||
return instance;
|
||||
@@ -84,7 +87,7 @@ void SoundEngine::StopAllSound3D()
|
||||
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)
|
||||
{
|
||||
@@ -102,18 +105,7 @@ void SoundEngine::UpdateSoundInstance(float fx, float fy, float fz, uint32_t dwc
|
||||
lastPlay = CTimer::Instance().GetCurrentSecond();
|
||||
}
|
||||
|
||||
if (isMain) // Sounds coming from main instance will always be played in 2d
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
PlaySound3D(c_rSoundInstance.strSoundFileName, fx, fy, fz);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +165,7 @@ void SoundEngine::SaveVolume(bool isMinimized)
|
||||
{
|
||||
constexpr float ratePerSecond = 1.0f / CS_CLIENT_FPS;
|
||||
// 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;
|
||||
if (m_MasterVolume <= outOfFocusVolume)
|
||||
@@ -199,14 +191,16 @@ void SoundEngine::SetMasterVolume(float volume)
|
||||
|
||||
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,
|
||||
float upX, float upY, float upZ)
|
||||
{
|
||||
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_direction(&m_Engine, 0, forwardX, forwardY, -forwardZ);
|
||||
ma_engine_listener_set_world_up(&m_Engine, 0, upX, -upY, upZ);
|
||||
}
|
||||
|
||||
void SoundEngine::SetListenerVelocity(float x, float y, float z)
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
@@ -78,6 +78,8 @@ private:
|
||||
bool Internal_LoadSoundFromPack(const std::string& name);
|
||||
|
||||
private:
|
||||
struct { float x, y, z; } m_CharacterPosition{};
|
||||
|
||||
ma_engine m_Engine{};
|
||||
std::unordered_map<std::string, std::vector<uint8_t>> m_Files;
|
||||
std::unordered_map<std::string, MaSoundInstance> m_Sounds2D;
|
||||
|
||||
@@ -55,7 +55,7 @@ void CEffectInstance::UpdateSound()
|
||||
m_matGlobal._43,
|
||||
m_dwFrame,
|
||||
m_pSoundInstanceVector,
|
||||
false, false);
|
||||
false);
|
||||
// NOTE : 매트릭스에서 위치를 직접 얻어온다 - [levites]
|
||||
}
|
||||
++m_dwFrame;
|
||||
|
||||
@@ -30,8 +30,7 @@ void CActorInstance::SoundEventProcess(BOOL bCheckFrequency)
|
||||
return;
|
||||
|
||||
const NSound::TSoundInstanceVector* c_pkVct_kSndInst = m_pkCurRaceMotionData->GetSoundInstanceVectorPointer();
|
||||
SoundEngine::Instance().UpdateSoundInstance(m_x, m_y, m_z, m_kCurMotNode.dwcurFrame, c_pkVct_kSndInst,
|
||||
bCheckFrequency, m_isMain);
|
||||
SoundEngine::Instance().UpdateSoundInstance(m_x, m_y, m_z, m_kCurMotNode.dwcurFrame, c_pkVct_kSndInst, bCheckFrequency);
|
||||
}
|
||||
|
||||
void CActorInstance::MotionEventProcess(DWORD dwcurFrame, int iIndex, const CRaceMotionData::TMotionEventData * c_pData)
|
||||
|
||||
Reference in New Issue
Block a user