expose sound Format property + improve property setter ranges

pull/47/head
cosmonaut 2023-03-07 13:44:01 -08:00
parent 4591920bf6
commit 771e6c234b
1 changed files with 12 additions and 8 deletions

View File

@ -7,7 +7,9 @@ namespace MoonWorks.Audio
public abstract class SoundInstance : AudioResource public abstract class SoundInstance : AudioResource
{ {
internal IntPtr Voice; internal IntPtr Voice;
internal FAudio.FAudioWaveFormatEx Format;
private FAudio.FAudioWaveFormatEx format;
public FAudio.FAudioWaveFormatEx Format => format;
protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings; protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings;
@ -24,6 +26,7 @@ namespace MoonWorks.Audio
get => pan; get => pan;
internal set internal set
{ {
value = Math.MathHelper.Clamp(value, -1f, 1f);
if (pan != value) if (pan != value)
{ {
pan = value; pan = value;
@ -58,9 +61,10 @@ namespace MoonWorks.Audio
get => pitch; get => pitch;
internal set internal set
{ {
value = Math.MathHelper.Clamp(value, -1f, 1f);
if (pitch != value) if (pitch != value)
{ {
pitch = Math.MathHelper.Clamp(value, -1f, 1f); pitch = value;
UpdatePitch(); UpdatePitch();
} }
} }
@ -72,6 +76,7 @@ namespace MoonWorks.Audio
get => volume; get => volume;
internal set internal set
{ {
value = Math.MathHelper.Max(0, value);
if (volume != value) if (volume != value)
{ {
volume = value; volume = value;
@ -95,9 +100,9 @@ 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) if (filterParameters.Frequency != value)
{ {
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_FREQUENCY);
filterParameters.Frequency = value; filterParameters.Frequency = value;
FAudio.FAudioVoice_SetFilterParameters( FAudio.FAudioVoice_SetFilterParameters(
@ -114,9 +119,9 @@ namespace MoonWorks.Audio
get => filterParameters.OneOverQ; get => filterParameters.OneOverQ;
internal set internal set
{ {
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_ONEOVERQ);
if (filterParameters.OneOverQ != value) if (filterParameters.OneOverQ != value)
{ {
value = System.Math.Clamp(value, 0.01f, MAX_FILTER_ONEOVERQ);
filterParameters.OneOverQ = value; filterParameters.OneOverQ = value;
FAudio.FAudioVoice_SetFilterParameters( FAudio.FAudioVoice_SetFilterParameters(
@ -181,6 +186,7 @@ namespace MoonWorks.Audio
{ {
if (ReverbEffect != null) if (ReverbEffect != null)
{ {
value = MathF.Max(0, value);
if (reverb != value) if (reverb != value)
{ {
reverb = value; reverb = value;
@ -221,7 +227,7 @@ namespace MoonWorks.Audio
uint samplesPerSecond uint samplesPerSecond
) : base(device) ) : base(device)
{ {
var format = new FAudio.FAudioWaveFormatEx format = new FAudio.FAudioWaveFormatEx
{ {
wFormatTag = formatTag, wFormatTag = formatTag,
wBitsPerSample = bitsPerSample, wBitsPerSample = bitsPerSample,
@ -231,12 +237,10 @@ namespace MoonWorks.Audio
nAvgBytesPerSec = blockAlign * samplesPerSecond nAvgBytesPerSec = blockAlign * samplesPerSecond
}; };
Format = format;
FAudio.FAudio_CreateSourceVoice( FAudio.FAudio_CreateSourceVoice(
Device.Handle, Device.Handle,
out Voice, out Voice,
ref Format, ref format,
FAudio.FAUDIO_VOICE_USEFILTER, FAudio.FAUDIO_VOICE_USEFILTER,
FAudio.FAUDIO_DEFAULT_FREQ_RATIO, FAudio.FAUDIO_DEFAULT_FREQ_RATIO,
IntPtr.Zero, IntPtr.Zero,