Skip to content

Commit

Permalink
better audio provider detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jklawreszuk committed Nov 7, 2024
1 parent 7e66eea commit 6ec7068
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 97 deletions.
2 changes: 2 additions & 0 deletions sources/engine/Stride.Audio/DynamicSoundSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ protected virtual bool CanFill
if (freeBuffer == null)
return false;

#if LINUX || OSX
freeBuffers.Enqueue(freeBuffer.Value);
#endif
return true;
}
}
Expand Down
9 changes: 2 additions & 7 deletions sources/engine/Stride.Audio/Layers/AudioLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Stride.Audio;
/// </summary>
public class AudioLayer
{
private static IAudioProvider al;
private static AudioProvider al;

static AudioLayer()
{
Expand All @@ -19,12 +19,7 @@ static AudioLayer()

public static void Init()
{
if(OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
al = new OpenALProvider();
if(OperatingSystem.IsAndroid())
al = new OpenSLESProvider();
// if(OperatingSystem.IsWindows())
// al = new XAudio2Provider();
al = new AudioProvider();
}

public static Device? Create(string deviceName, DeviceFlags flags)
Expand Down
38 changes: 0 additions & 38 deletions sources/engine/Stride.Audio/Layers/IAudioProvider.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ namespace Stride.Audio;

public partial class AudioBuffer : IInitializable
{
#if LINUX || OSX
public short[] Pcm { get; internal set; }
public int Size { get; internal set; }
public int SampleRate { get; internal set; }
public BufferType Type { get; internal set; }
public bool Initialized { get; internal set; }
public uint Value;
#endif
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if LINUX || OSX
using System;
using System.Runtime.InteropServices;
using Silk.NET.OpenAL;
using Stride.Core.Mathematics;

namespace Stride.Audio;

internal sealed unsafe class OpenALProvider : IAudioProvider
internal sealed unsafe class AudioProvider
{
private readonly ALContext alc;
private readonly AL al;
public OpenALProvider()
public AudioProvider()
{
alc = ALContext.GetApi();
al = AL.GetApi();
Expand Down Expand Up @@ -424,4 +425,5 @@ public void Update(Device device)
}
device.DeviceLock.Unlock();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

#if LINUX || OSX
using System.Collections.Generic;

namespace Stride.Audio;
Expand All @@ -10,3 +12,4 @@ public struct Device()
public List<Listener> Listeners { get; internal set; } = [];
public unsafe Silk.NET.OpenAL.Device* Value { get; internal set; }
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if LINUX || OSX
using System.Collections.Generic;

namespace Stride.Audio;
Expand All @@ -11,4 +12,5 @@ public struct Listener() : IInitializable
public unsafe Silk.NET.OpenAL.Context* Context { get; internal set; }
public Dictionary<uint, AudioBuffer> Buffers { get; internal set; } = [];
public bool Initialized { get; internal set; }
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if LINUX || OSX

using System.Collections.Generic;

namespace Stride.Audio;
Expand All @@ -19,3 +21,4 @@ public struct Source() : IInitializable
public uint Sources;
internal uint Value;
}
#endif
6 changes: 4 additions & 2 deletions sources/engine/Stride.Audio/Layers/OpenSLESProvider.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#if ANDROID
using Stride.Core.Mathematics;

namespace Stride.Audio;

internal class OpenSLESProvider : IAudioProvider
internal class OpenSLESProvider
{
public AudioBuffer BufferCreate(int maxBufferSizeBytes)
{
Expand Down Expand Up @@ -150,4 +151,5 @@ public void Update(Device device)
{
throw new System.NotImplementedException();
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

#if WINDOWS
using Silk.NET.XAudio;

namespace Stride.Audio;
Expand All @@ -9,7 +11,8 @@ public sealed partial class AudioBuffer : IInitializable
internal uint length;
internal Buffer buffer = new();
internal BufferType type;
public XAudioBuffer(int maxBufferSizeBytes)
public bool Initialized => true;
public AudioBuffer(int maxBufferSizeBytes)
{
buffer = new();
unsafe
Expand All @@ -19,3 +22,4 @@ public XAudioBuffer(int maxBufferSizeBytes)
}
}
}
#endif
Loading

0 comments on commit 6ec7068

Please sign in to comment.