feat(sound): add SESound::SetChannelGroup

This commit is contained in:
fallenoak 2025-11-29 12:24:17 -06:00
parent d5cebf9a02
commit 873342dba8
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
5 changed files with 36 additions and 1 deletions

View File

@ -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<intptr_t>(channelGroup) - reinterpret_cast<intptr_t>(SESound::s_ChannelGroups.m_data);
auto channelGroupIndex = static_cast<int32_t>(channelGroupOffset / sizeof(SEChannelGroup));
this->m_internal->m_channelGroup = channelGroupIndex;
this->m_internal->UpdateVolume();
}
void SESound::SetFadeInTime(float fadeInTime) {
if (!this->m_internal) {
return;

View File

@ -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);

View File

@ -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();

View File

@ -41,6 +41,7 @@ class SESoundInternal : public TSLinkedNode<SESoundInternal> {
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> {
SESoundInternal();
float GetVolume();
void Play();
void UpdateVolume();
};
class SEDiskSound : public SESoundInternal {

View File

@ -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 : "<UNKNOWN ERROR>";