Skip to content

Commit

Permalink
prevent ambient sounds stuttering during tedious travel
Browse files Browse the repository at this point in the history
Tedious Travel increases time acceleration, and ambient sounds start
interruption one another. This patch prevents ambient sounds for
starting if another one is still playing.

It doesn't sound perfect on my rig, maybe performance issues are at play
too.
  • Loading branch information
Pierre Etchemaite committed Mar 3, 2019
1 parent 82bb29a commit ffe40b4
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Assets/Scripts/Game/AmbientEffectsPlayer.cs
Expand Up @@ -174,27 +174,36 @@ private AudioClip PlayLoop(SoundClips clip, float volumeScale)

private void AmbientPlayOneShot(SoundClips clip, float volumeScale)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.spatialBlend = 0;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
if (!ambientAudioSource.isPlaying)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.spatialBlend = 0;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
}
}

private void SpatializedPlayOneShot(SoundClips clip, Vector3 position, float volumeScale)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.transform.position = position;
ambientAudioSource.spatialBlend = 1f;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
if (!ambientAudioSource.isPlaying)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.transform.position = position;
ambientAudioSource.spatialBlend = 1f;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
}
}

private void RelativePlayOneShot(SoundClips clip, Vector3 relativePosition, float volumeScale)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.spatialBlend = 1f;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
if (relativePositionCoroutine != null)
StopCoroutine(relativePositionCoroutine);
relativePositionCoroutine = StartCoroutine(UpdateAmbientSoundRelativePosition(relativePosition));
if (!ambientAudioSource.isPlaying)
{
AudioClip audioClip = dfAudioSource.GetAudioClip((int)clip);
ambientAudioSource.spatialBlend = 1f;
ambientAudioSource.PlayOneShotWhenReady(audioClip, volumeScale);
if (relativePositionCoroutine != null)
StopCoroutine(relativePositionCoroutine);
relativePositionCoroutine = StartCoroutine(UpdateAmbientSoundRelativePosition(relativePosition));
}
}

private IEnumerator UpdateAmbientSoundRelativePosition(Vector3 relativePosition)
Expand Down

0 comments on commit ffe40b4

Please sign in to comment.