feature: change playing sound property

This commit is contained in:
2026-04-23 19:32:06 +08:00
parent f38103d2dc
commit 401dfc69b2
5 changed files with 242 additions and 43 deletions
@@ -99,6 +99,62 @@ namespace OCES.Audio
}
}
internal void SetVolume(uint audioId, float targetVolume)
{
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
foreach (ActiveSound target in targets)
{
target.Volume = targetVolume;
if (target.Source)
{
target.Source.volume = targetVolume;
}
}
}
internal void SetPitch(uint audioId, float targetPitch)
{
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
foreach (ActiveSound target in targets)
{
target.Pitch = targetPitch;
if (target.Source)
{
target.Source.pitch = targetPitch;
}
}
}
internal void ResetVolume(uint audioId)
{
double now = Time.realtimeSinceStartupAsDouble * 1000.0;
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
foreach (ActiveSound target in targets)
{
float defaultVolume = this.m_volumeStepResolver.ResolveVolume(target.AudioObject, now);
target.Volume = defaultVolume;
if (target.Source)
{
target.Source.volume = defaultVolume;
}
}
}
internal void ResetPitch(uint audioId)
{
double now = Time.realtimeSinceStartupAsDouble * 1000.0;
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
foreach (ActiveSound target in targets)
{
float defaultPitch = this.m_pitchStepResolver.ResolvePitch(target.AudioObject, now);
target.Pitch = defaultPitch;
if (target.Source != null)
{
target.Source.pitch = defaultPitch;
}
}
}
// ─────────────────────────────────────────────
// 节流 & 调度入口
// ─────────────────────────────────────────────