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