Skip to content

Commit 21ecfc1

Browse files
committed
Port XAudio to Silk.NET
1 parent ffe8c36 commit 21ecfc1

20 files changed

+811
-160
lines changed

sources/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<PackageVersion Include="Silk.NET.Sdl" Version="2.20.0" />
2929
<PackageVersion Include="Silk.NET.Windowing.Sdl" Version="2.19.0" />
3030
<PackageVersion Include="Silk.NET.OpenAL" Version="2.21.0" />
31+
<PackageVersion Include="Silk.NET.XAudio" Version="2.21.0" />
3132
<PackageVersion Include="Stride.SharpFont" Version="1.0.1" />
3233
<PackageVersion Include="System.Drawing.Common" Version="8.0.1" />
3334
<PackageVersion Include="System.Memory" Version="4.5.5" />

sources/engine/Stride.Audio/Layers/AudioLayer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static void Init()
2323
al = new OpenALProvider();
2424
if(OperatingSystem.IsAndroid())
2525
al = new OpenSLESProvider();
26-
if(OperatingSystem.IsWindows())
27-
al = new XAudio2Provider();
26+
// if(OperatingSystem.IsWindows())
27+
// al = new XAudio2Provider();
2828
}
2929

3030
public static Device? Create(string deviceName, DeviceFlags flags)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Stride.Audio.Layers.XAudio;
2+
3+
internal struct HrtfApoInit(HrtfDirectivity directivity)
4+
{
5+
HrtfDirectivity directivity = directivity;
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
namespace Stride.Audio.Layers.XAudio;
4+
5+
internal class HrtfDirectivity
6+
{
7+
public readonly HrtfDirectivityType omniDirectional;
8+
public readonly float hrtfDirectionFactor;
9+
10+
public HrtfDirectivity(HrtfDirectivityType omniDirectional, float hrtfDirectionFactor)
11+
{
12+
this.omniDirectional = omniDirectional;
13+
this.hrtfDirectionFactor = hrtfDirectionFactor;
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Stride.Audio.Layers.XAudio;
2+
3+
// Indicates one of several stock directivity patterns.
4+
public enum HrtfDirectivityType
5+
{
6+
// The sound emission is in all directions.
7+
OmniDirectional = 0,
8+
// The sound emission is a cardiod shape.
9+
Cardioid,
10+
// The sound emission is a cone.
11+
Cone
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
using System;
4+
5+
namespace Stride.Audio.Layers.XAudio;
6+
7+
using System.Runtime.InteropServices;
8+
9+
[Guid("15B3CD66-E9DE-4464-B6E6-2BC3CF63D455")]
10+
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
11+
public interface IXAPOHrtfParameters
12+
{
13+
/// <summary>
14+
/// The position of the sound relative to the listener.
15+
/// </summary>
16+
/// <param name="position">Pointer to the HrtfPosition structure containing the position.</param>
17+
void SetSourcePosition(ref HrtfPosition position);
18+
19+
/// <summary>
20+
/// The rotation matrix for the source orientation, with respect to the listener's frame of reference (the listener's coordinate system).
21+
/// </summary>
22+
/// <param name="orientation">Pointer to the HrtfOrientation structure containing the orientation.</param>
23+
void SetSourceOrientation(ref HrtfOrientation orientation);
24+
25+
/// <summary>
26+
/// The custom direct path gain value for the current source position. Valid only for sounds played with the HrtfDistanceDecayType. Custom decay type.
27+
/// </summary>
28+
/// <param name="gain">The gain value.</param>
29+
void SetSourceGain(float gain);
30+
31+
/// <summary>
32+
/// Selects the acoustic environment to simulate.
33+
/// </summary>
34+
/// <param name="environment">The environment to be simulated.</param>
35+
void SetEnvironment(HrtfEnvironment environment);
36+
}
37+
38+
[StructLayout(LayoutKind.Sequential)]
39+
public struct HrtfPosition
40+
{
41+
public float x;
42+
public float y;
43+
public float z;
44+
}
45+
46+
[StructLayout(LayoutKind.Sequential)]
47+
public struct HrtfOrientation
48+
{
49+
public float[] element;
50+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
namespace Stride.Audio
4+
{
5+
internal class X3DAUDIO_HANDLE
6+
{
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
namespace Stride.Audio.Layers.XAudio;
4+
5+
internal struct X3DAudioCone
6+
{
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
namespace Stride.Audio.Layers.XAudio;
4+
5+
public unsafe struct X3DAudioDSPSettings
6+
{
7+
public float* pMatrixCoefficients; // [inout] matrix coefficient table, receives an array representing the volume level used to send from source channel S to destination channel D, stored as pMatrixCoefficients[SrcChannelCount * D + S], must have at least SrcChannelCount*DstChannelCount elements
8+
public float* pDelayTimes; // [inout] delay time array, receives delays for each destination channel in milliseconds, must have at least DstChannelCount elements (stereo final mix only)
9+
public uint SrcChannelCount; // [in] number of source channels, must equal number of channels in respective emitter
10+
public uint DstChannelCount; // [in] number of destination channels, must equal number of channels of the final mix
11+
12+
public float LPFDirectCoefficient; // [out] LPF direct-path coefficient
13+
float LPFReverbCoefficient; // [out] LPF reverb-path coefficient
14+
float ReverbLevel; // [out] reverb send level
15+
public float DopplerFactor; // [out] doppler shift factor, scales resampler ratio for doppler shift effect, where the effective frequency = DopplerFactor * original frequency
16+
float EmitterToListenerAngle; // [out] emitter-to-listener interior angle, expressed in radians with respect to the emitter's front orientation
17+
18+
float EmitterToListenerDistance; // [out] distance in user-defined world units from the emitter base to listener position, always calculated
19+
float EmitterVelocityComponent; // [out] component of emitter velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler
20+
float ListenerVelocityComponent; // [out] component of listener velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2+
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
namespace Stride.Audio.Layers.XAudio;
4+
5+
internal unsafe struct X3DAudioDistanceCurve
6+
{
7+
public X3DAudioDistanceCurvePoint* pPoints; // distance curve point array, must have at least PointCount elements with no duplicates and be sorted in ascending order with respect to Distance
8+
public uint PointCount; // number of distance curve points, must be >= 2 as all distance curves must have at least two endpoints, defining DSP settings at 0.0f and 1.0f normalized distance
9+
}

0 commit comments

Comments
 (0)