add SourceVoice.Apply3D

pull/50/head
cosmonaut 2023-08-02 18:33:16 -07:00
parent 9a854506f3
commit 8d5ac8e17b
2 changed files with 38 additions and 3 deletions

View File

@ -139,6 +139,41 @@ namespace MoonWorks.Audio
Submit(buffer.ToFAudioBuffer());
}
public unsafe void Apply3D(AudioListener listener, AudioEmitter emitter)
{
Is3D = true;
emitter.emitterData.CurveDistanceScaler = Device.CurveDistanceScalar;
emitter.emitterData.ChannelCount = SourceChannelCount;
var dspSettings = new FAudio.F3DAUDIO_DSP_SETTINGS
{
DopplerFactor = DopplerFactor,
SrcChannelCount = SourceChannelCount,
DstChannelCount = DestinationChannelCount,
pMatrixCoefficients = (nint) pMatrixCoefficients
};
FAudio.F3DAudioCalculate(
Device.Handle3D,
ref listener.listenerData,
ref emitter.emitterData,
FAudio.F3DAUDIO_CALCULATE_MATRIX | FAudio.F3DAUDIO_CALCULATE_DOPPLER,
ref dspSettings
);
UpdatePitch();
FAudio.FAudioVoice_SetOutputMatrix(
Handle,
OutputVoice.Handle,
SourceChannelCount,
DestinationChannelCount,
(nint) pMatrixCoefficients,
0
);
}
/// <summary>
/// Specifies that this source voice can be returned to the voice pool.
/// Holding on to the reference after calling this will cause problems!

View File

@ -12,10 +12,10 @@ namespace MoonWorks.Audio
public uint SourceChannelCount { get; }
public uint DestinationChannelCount { get; }
private SubmixVoice OutputVoice;
protected SubmixVoice OutputVoice;
private ReverbEffect ReverbEffect;
byte* pMatrixCoefficients;
protected byte* pMatrixCoefficients;
public bool Is3D { get; protected set; }
@ -447,7 +447,7 @@ namespace MoonWorks.Audio
SetOutputVoice(Device.MasteringVoice);
}
private void UpdatePitch()
protected void UpdatePitch()
{
float doppler;
float dopplerScale = Device.DopplerScale;