2023-03-02 01:47:09 +00:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace MoonWorks.Audio
|
|
|
|
{
|
2023-08-03 19:54:02 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Use this in conjunction with SourceVoice.SetReverbEffectChain to add reverb to a voice.
|
|
|
|
/// </summary>
|
|
|
|
public unsafe class ReverbEffect : SubmixVoice
|
2023-03-02 01:47:09 +00:00
|
|
|
{
|
2023-09-12 22:24:45 +00:00
|
|
|
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
|
|
|
public static FAudio.FAudioFXReverbParameters DefaultParams = new FAudio.FAudioFXReverbParameters
|
|
|
|
{
|
|
|
|
WetDryMix = 100.0f,
|
|
|
|
ReflectionsDelay = 7,
|
|
|
|
ReverbDelay = 11,
|
|
|
|
RearDelay = FAudio.FAUDIOFX_REVERB_DEFAULT_REAR_DELAY,
|
|
|
|
PositionLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION,
|
|
|
|
PositionRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION,
|
|
|
|
PositionMatrixLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX,
|
|
|
|
PositionMatrixRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX,
|
|
|
|
EarlyDiffusion = 15,
|
|
|
|
LateDiffusion = 15,
|
|
|
|
LowEQGain = 8,
|
|
|
|
LowEQCutoff = 4,
|
|
|
|
HighEQGain = 8,
|
|
|
|
HighEQCutoff = 6,
|
|
|
|
RoomFilterFreq = 5000f,
|
|
|
|
RoomFilterMain = -10f,
|
|
|
|
RoomFilterHF = -1f,
|
|
|
|
ReflectionsGain = -26.0200005f,
|
|
|
|
ReverbGain = 10.0f,
|
|
|
|
DecayTime = 1.49000001f,
|
|
|
|
Density = 100.0f,
|
|
|
|
RoomSize = FAudio.FAUDIOFX_REVERB_DEFAULT_ROOM_SIZE
|
|
|
|
};
|
|
|
|
|
2023-08-03 19:54:02 +00:00
|
|
|
public ReverbEffect(AudioDevice audioDevice, uint processingStage) : base(audioDevice, 1, audioDevice.DeviceDetails.OutputFormat.Format.nSamplesPerSec, processingStage)
|
2023-03-02 01:47:09 +00:00
|
|
|
{
|
|
|
|
/* Init reverb */
|
|
|
|
IntPtr reverb;
|
|
|
|
FAudio.FAudioCreateReverb(out reverb, 0);
|
|
|
|
|
2023-08-03 19:54:02 +00:00
|
|
|
var chain = new FAudio.FAudioEffectChain();
|
2023-09-12 22:24:45 +00:00
|
|
|
var descriptor = new FAudio.FAudioEffectDescriptor
|
|
|
|
{
|
|
|
|
InitialState = 1,
|
|
|
|
OutputChannels = 1,
|
|
|
|
pEffect = reverb
|
|
|
|
};
|
2023-03-02 01:47:09 +00:00
|
|
|
|
2023-08-03 19:54:02 +00:00
|
|
|
chain.EffectCount = 1;
|
|
|
|
chain.pEffectDescriptors = (nint) (&descriptor);
|
2023-03-02 01:47:09 +00:00
|
|
|
|
2023-08-03 19:54:02 +00:00
|
|
|
FAudio.FAudioVoice_SetEffectChain(
|
|
|
|
Handle,
|
|
|
|
ref chain
|
2023-03-02 01:47:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FAudio.FAPOBase_Release(reverb);
|
|
|
|
|
2023-09-12 22:24:45 +00:00
|
|
|
SetParams(DefaultParams);
|
2023-03-02 01:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetParams(in FAudio.FAudioFXReverbParameters reverbParams)
|
|
|
|
{
|
|
|
|
fixed (FAudio.FAudioFXReverbParameters* reverbParamsPtr = &reverbParams)
|
|
|
|
{
|
|
|
|
FAudio.FAudioVoice_SetEffectParameters(
|
2023-08-03 19:54:02 +00:00
|
|
|
Handle,
|
2023-03-02 01:47:09 +00:00
|
|
|
0,
|
|
|
|
(nint) reverbParamsPtr,
|
|
|
|
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|