diff --git a/src/sound/SESound.cpp b/src/sound/SESound.cpp index 8ac2019..f306b2a 100644 --- a/src/sound/SESound.cpp +++ b/src/sound/SESound.cpp @@ -679,6 +679,26 @@ void SESound::Play() { } } +void SESound::SetChannelGroup(const char* name, bool inMaster) { + if (!this->m_internal) { + return; + } + + if (!SESound::s_Initialized || !name) { + return; + } + + auto channelGroup = SESound::GetChannelGroup(name, true, inMaster); + + // Get index in array (probably a member function on TSBaseArray) + auto channelGroupOffset = reinterpret_cast(channelGroup) - reinterpret_cast(SESound::s_ChannelGroups.m_data); + auto channelGroupIndex = static_cast(channelGroupOffset / sizeof(SEChannelGroup)); + + this->m_internal->m_channelGroup = channelGroupIndex; + + this->m_internal->UpdateVolume(); +} + void SESound::SetFadeInTime(float fadeInTime) { if (!this->m_internal) { return; diff --git a/src/sound/SESound.hpp b/src/sound/SESound.hpp index 36211c1..007ab80 100644 --- a/src/sound/SESound.hpp +++ b/src/sound/SESound.hpp @@ -45,6 +45,7 @@ class SESound { bool IsPlaying(); int32_t Load(const char* filename, int32_t a3, FMOD::SoundGroup* soundGroup1, FMOD::SoundGroup* soundGroup2, bool a6, bool a7, uint32_t a8, int32_t a9, uint32_t a10); void Play(); + void SetChannelGroup(const char* name, bool inMaster); void SetFadeInTime(float fadeInTime); void SetFadeOutTime(float fadeOutTime); void SetUserData(SEUserData* userData); diff --git a/src/sound/SESoundInternal.cpp b/src/sound/SESoundInternal.cpp index bf6ff4b..23fa907 100644 --- a/src/sound/SESoundInternal.cpp +++ b/src/sound/SESoundInternal.cpp @@ -43,6 +43,14 @@ void SESoundInternal::Play() { } } +void SESoundInternal::UpdateVolume() { + if (!this->m_fmodChannel) { + return; + } + + this->m_fmodChannel->setVolume(this->GetVolume()); +} + SEDiskSound::SEDiskSound() : SESoundInternal() { SESound::s_InternalCritSect.Enter(); diff --git a/src/sound/SESoundInternal.hpp b/src/sound/SESoundInternal.hpp index 7f83aa6..1f5d16f 100644 --- a/src/sound/SESoundInternal.hpp +++ b/src/sound/SESoundInternal.hpp @@ -41,6 +41,7 @@ class SESoundInternal : public TSLinkedNode { int32_t m_useCache = 0; int32_t m_type = 0; // TODO + int32_t m_channelGroup = 0; FMOD_MODE m_fmodMode = FMOD_DEFAULT; uint8_t m_playing = 0; uint8_t m_stopped = 0; @@ -53,6 +54,7 @@ class SESoundInternal : public TSLinkedNode { SESoundInternal(); float GetVolume(); void Play(); + void UpdateVolume(); }; class SEDiskSound : public SESoundInternal { diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index 266c775..cdea6cf 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -414,7 +414,11 @@ int32_t SI2::PlaySoundKit(int32_t id, int32_t a2, SOUNDKITOBJECT* object, SoundK } } - // TODO + // Set channel group based on sound type + + sound->SetChannelGroup(SI2::s_ChannelGroupNames[properties->m_type], properties->m_type != 3); + + // Set user data auto userData = STORM_NEW(SI2USERDATA); userData->m_name = soundKitDef->name ? soundKitDef->name : "";