Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC curves are now updated before Cue is played #5709

Merged
merged 1 commit into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions MonoGame.Framework/Audio/Xact/Cue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public void Play()
var index = XactHelpers.Random.Next(_sounds.Length);
_curSound = _sounds[index];

_curSound.Play(1.0f, _engine);
var volume = UpdateRpcCurves();

_curSound.Play(volume, _engine);
_played = true;
IsPrepared = false;
}
Expand Down Expand Up @@ -253,14 +255,22 @@ public void Apply3D(AudioListener listener, AudioEmitter emitter)

internal void Update(float dt)
{
if (_curSound != null)
_curSound.Update(dt);
if (_curSound == null)
return;

_curSound.Update(dt);

UpdateRpcCurves();
}

private float UpdateRpcCurves()
{
var volume = 1.0f;

// Evaluate the runtime parameter controls.
var rpcCurves = _curSound.RpcCurves;
if (rpcCurves.Length > 0)
{
var volume = 1.0f;
var pitch = 0.0f;
var reverbMix = 1.0f;
float? filterFrequency = null;
Expand Down Expand Up @@ -305,8 +315,12 @@ internal void Update(float dt)
}
}

pitch = MathHelper.Clamp(pitch, -1.0f, 1.0f);

_curSound.UpdateState(_engine, volume, pitch, reverbMix, filterFrequency, filterQFactor);
}

return volume;
}

/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions MonoGame.Framework/Audio/Xact/SoundBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public SoundBank(AudioEngine audioEngine, string fileName)
stream.Seek(complexCuesOffset, SeekOrigin.Begin);
for (int i = 0; i < numComplexCues; i++)
{
//Cue cue;

byte flags = reader.ReadByte();
if (((flags >> 2) & 1) != 0)
{
Expand Down Expand Up @@ -348,9 +346,6 @@ private void Dispose(bool disposing)

if (disposing)
{
//foreach (var cue in _cues.Values)
// cue.Dispose();

IsInUse = false;

if (Disposing != null)
Expand Down
15 changes: 11 additions & 4 deletions MonoGame.Framework/Audio/Xact/XactSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public void Play(float volume, AudioEngine engine)
{
_cueVolume = volume;
var category = engine.Categories[_categoryID];
UpdateCategoryVolume(category._volume[0]);

var curInstances = category.GetPlayingInstanceCount();
if (curInstances >= category.maxInstances)
Expand All @@ -141,10 +140,17 @@ public void Play(float volume, AudioEngine engine)
}
}

float finalVolume = _volume * _cueVolume * category._volume[0];
float finalPitch = _pitch + _cuePitch;
float finalMix = _useReverb ? _cueReverbMix : 0.0f;

if (_complexSound)
{
foreach (XactClip clip in _soundClips)
{
clip.UpdateState(finalVolume, finalPitch, finalMix, _cueFilterFrequency, _cueFilterQFactor);
clip.Play();
}
}
else
{
Expand All @@ -160,9 +166,9 @@ public void Play(float volume, AudioEngine engine)
return;
}

_wave.Pitch = _pitch + _cuePitch;
_wave.Volume = _volume * _cueVolume * category._volume[0];
_wave.PlatformSetReverbMix(_useReverb ? _cueReverbMix : 0.0f);
_wave.Pitch = finalPitch;
_wave.Volume = finalVolume;
_wave.PlatformSetReverbMix(finalMix);
_wave.Play();
}
}
Expand Down Expand Up @@ -295,6 +301,7 @@ internal void UpdateState(AudioEngine engine, float volume, float pitch, float r
{
_wave.PlatformSetReverbMix(_useReverb ? _cueReverbMix : 0.0f);
_wave.Pitch = finalPitch;
_wave.Volume = finalVolume;
}
}

Expand Down