avoid calling into FAudio if property did not change

pull/47/head
cosmonaut 2023-03-06 17:16:28 -08:00
parent d69f62d2ce
commit 4d41d230af
1 changed files with 89 additions and 71 deletions

View File

@ -23,6 +23,8 @@ namespace MoonWorks.Audio
{
get => pan;
internal set
{
if (pan != value)
{
pan = value;
@ -48,28 +50,35 @@ namespace MoonWorks.Audio
);
}
}
}
private float pitch = 0;
public float Pitch
{
get => pitch;
internal set
{
if (pitch != value)
{
pitch = Math.MathHelper.Clamp(value, -1f, 1f);
UpdatePitch();
}
}
}
private float volume = 1;
public float Volume
{
get => volume;
internal set
{
if (volume != value)
{
volume = value;
FAudio.FAudioVoice_SetVolume(Voice, volume, 0);
}
}
}
private const float MAX_FILTER_FREQUENCY = 1f;
private const float MAX_FILTER_ONEOVERQ = 1.5f;
@ -85,6 +94,8 @@ namespace MoonWorks.Audio
{
get => filterParameters.Frequency;
internal set
{
if (filterParameters.Frequency != value)
{
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_FREQUENCY);
filterParameters.Frequency = value;
@ -96,6 +107,7 @@ namespace MoonWorks.Audio
);
}
}
}
private float FilterOneOverQ
{
@ -118,6 +130,8 @@ namespace MoonWorks.Audio
{
get => filterType;
set
{
if (filterType != value)
{
filterType = value;
@ -152,6 +166,7 @@ namespace MoonWorks.Audio
);
}
}
}
private float reverb;
public unsafe float Reverb
@ -160,6 +175,8 @@ namespace MoonWorks.Audio
internal set
{
if (ReverbEffect != null)
{
if (reverb != value)
{
reverb = value;
@ -179,6 +196,7 @@ namespace MoonWorks.Audio
0
);
}
}
#if DEBUG
if (ReverbEffect == null)