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

@ -24,28 +24,31 @@ namespace MoonWorks.Audio
get => pan; get => pan;
internal set internal set
{ {
pan = value; if (pan != value)
if (pan < -1f)
{ {
pan = -1f; pan = value;
}
if (pan > 1f)
{
pan = 1f;
}
if (Is3D) { return; } if (pan < -1f)
{
pan = -1f;
}
if (pan > 1f)
{
pan = 1f;
}
SetPanMatrixCoefficients(); if (Is3D) { return; }
FAudio.FAudioVoice_SetOutputMatrix(
Voice, SetPanMatrixCoefficients();
Device.MasteringVoice, FAudio.FAudioVoice_SetOutputMatrix(
dspSettings.SrcChannelCount, Voice,
dspSettings.DstChannelCount, Device.MasteringVoice,
dspSettings.pMatrixCoefficients, dspSettings.SrcChannelCount,
0 dspSettings.DstChannelCount,
); dspSettings.pMatrixCoefficients,
0
);
}
} }
} }
@ -55,8 +58,11 @@ namespace MoonWorks.Audio
get => pitch; get => pitch;
internal set internal set
{ {
pitch = Math.MathHelper.Clamp(value, -1f, 1f); if (pitch != value)
UpdatePitch(); {
pitch = Math.MathHelper.Clamp(value, -1f, 1f);
UpdatePitch();
}
} }
} }
@ -66,8 +72,11 @@ namespace MoonWorks.Audio
get => volume; get => volume;
internal set internal set
{ {
volume = value; if (volume != value)
FAudio.FAudioVoice_SetVolume(Voice, volume, 0); {
volume = value;
FAudio.FAudioVoice_SetVolume(Voice, volume, 0);
}
} }
} }
@ -86,14 +95,17 @@ namespace MoonWorks.Audio
get => filterParameters.Frequency; get => filterParameters.Frequency;
internal set internal set
{ {
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_FREQUENCY); if (filterParameters.Frequency != value)
filterParameters.Frequency = value; {
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_FREQUENCY);
filterParameters.Frequency = value;
FAudio.FAudioVoice_SetFilterParameters( FAudio.FAudioVoice_SetFilterParameters(
Voice, Voice,
ref filterParameters, ref filterParameters,
0 0
); );
}
} }
} }
@ -119,37 +131,40 @@ namespace MoonWorks.Audio
get => filterType; get => filterType;
set set
{ {
filterType = value; if (filterType != value)
switch (filterType)
{ {
case FilterType.None: filterType = value;
filterParameters = new FAudio.FAudioFilterParameters
{
Type = FAudio.FAudioFilterType.FAudioLowPassFilter,
Frequency = 1f,
OneOverQ = 1f
};
break;
case FilterType.LowPass: switch (filterType)
filterParameters.Type = FAudio.FAudioFilterType.FAudioLowPassFilter; {
break; case FilterType.None:
filterParameters = new FAudio.FAudioFilterParameters
{
Type = FAudio.FAudioFilterType.FAudioLowPassFilter,
Frequency = 1f,
OneOverQ = 1f
};
break;
case FilterType.BandPass: case FilterType.LowPass:
filterParameters.Type = FAudio.FAudioFilterType.FAudioBandPassFilter; filterParameters.Type = FAudio.FAudioFilterType.FAudioLowPassFilter;
break; break;
case FilterType.HighPass: case FilterType.BandPass:
filterParameters.Type = FAudio.FAudioFilterType.FAudioHighPassFilter; filterParameters.Type = FAudio.FAudioFilterType.FAudioBandPassFilter;
break; break;
case FilterType.HighPass:
filterParameters.Type = FAudio.FAudioFilterType.FAudioHighPassFilter;
break;
}
FAudio.FAudioVoice_SetFilterParameters(
Voice,
ref filterParameters,
0
);
} }
FAudio.FAudioVoice_SetFilterParameters(
Voice,
ref filterParameters,
0
);
} }
} }
@ -161,23 +176,26 @@ namespace MoonWorks.Audio
{ {
if (ReverbEffect != null) if (ReverbEffect != null)
{ {
reverb = value; if (reverb != value)
float* outputMatrix = (float*) dspSettings.pMatrixCoefficients;
outputMatrix[0] = reverb;
if (dspSettings.SrcChannelCount == 2)
{ {
outputMatrix[1] = reverb; reverb = value;
}
FAudio.FAudioVoice_SetOutputMatrix( float* outputMatrix = (float*) dspSettings.pMatrixCoefficients;
Voice, outputMatrix[0] = reverb;
ReverbEffect.Voice, if (dspSettings.SrcChannelCount == 2)
dspSettings.SrcChannelCount, {
1, outputMatrix[1] = reverb;
dspSettings.pMatrixCoefficients, }
0
); FAudio.FAudioVoice_SetOutputMatrix(
Voice,
ReverbEffect.Voice,
dspSettings.SrcChannelCount,
1,
dspSettings.pMatrixCoefficients,
0
);
}
} }
#if DEBUG #if DEBUG