Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ TestResult.xml
nunit-*.xml

publish
publish.sh
publish.sh

# Desktop specific
.DS_Store
2 changes: 1 addition & 1 deletion GraphAudio.Kit/GraphAudio.Kit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="GraphAudio.Core" Version="0.4.1" />
<PackageReference Include="GraphAudio.IO" Version="0.4.1" />
<PackageReference Include="GraphAudio.Realtime" Version="0.4.3" />
<PackageReference Include="GraphAudio.SteamAudio" Version="0.4.2" />
<PackageReference Include="GraphAudio.SteamAudio" Version="0.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GraphAudio.SteamAudio/GraphAudio.SteamAudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Authors>the-byte-bender</Authors>
<Description>Spatial audio for GraphAudio using Steam Audio</Description>
<Copyright>2025</Copyright>
<Version>0.4.2</Version>
<Version>0.4.3</Version>
<PackageId>GraphAudio.SteamAudio</PackageId>
<PackageProjectUrl>https://github.com/the-byte-bender/GraphAudio</PackageProjectUrl>
<RepositoryUrl>https://github.com/the-byte-bender/GraphAudio</RepositoryUrl>
Expand Down
1 change: 1 addition & 0 deletions GraphAudio.SteamAudio/SteamAudioContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private static SteamAudioResources GetOrCreate(AudioContextBase context)
{
return _contextMap.GetOrAdd(context, ctx =>
{
SteamAudioNativeLoader.EnsureLoaded();
var resources = new SteamAudioResources(ctx.SampleRate, AudioBuffer.FramesPerBlock);

var contextSettings = new IPL.ContextSettings
Expand Down
99 changes: 99 additions & 0 deletions GraphAudio.SteamAudio/SteamAudioNativeLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

namespace GraphAudio.SteamAudio;

/// <summary>
/// Handles native library loading for SteamAudio on macOS where the NuGet package
/// uses osx-universal RID instead of osx-arm64/osx-x64.
/// </summary>
internal static class SteamAudioNativeLoader
{
private static bool _isRegistered = false;
private static readonly object _lock = new object();

/// <summary>
/// Registers the DllImport resolver for SteamAudio native libraries.
/// </summary>
internal static void EnsureLoaded()
{
lock (_lock)
{
if (_isRegistered) return;

var steamAudioAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.GetName().Name == "SteamAudio.NET");

if (steamAudioAssembly != null)
{
NativeLibrary.SetDllImportResolver(steamAudioAssembly, DllImportResolver);
}

_isRegistered = true;
}
}

private static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
if (!libraryName.Equals("phonon.dll", StringComparison.OrdinalIgnoreCase) &&
!libraryName.Equals("phonon", StringComparison.OrdinalIgnoreCase))
{
return IntPtr.Zero;
}

// Try base directory first (for .app bundles where dylibs are in MacOS/)
var baseDirectoryPath = GetBaseDirectoryPath();
if (baseDirectoryPath != null && File.Exists(baseDirectoryPath))
{
if (NativeLibrary.TryLoad(baseDirectoryPath, out var handle))
return handle;
}

var archSpecificPath = GetArchitectureSpecificPath();
if (archSpecificPath != null && File.Exists(archSpecificPath))
{
if (NativeLibrary.TryLoad(archSpecificPath, out var handle))
return handle;
}

var universalPath = GetUniversalPath();
if (universalPath != null && File.Exists(universalPath))
{
if (NativeLibrary.TryLoad(universalPath, out var handle))
return handle;
}

return IntPtr.Zero;
}

private static string? GetBaseDirectoryPath()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return null;

return Path.Combine(AppContext.BaseDirectory, "libphonon.dylib");
}

private static string? GetArchitectureSpecificPath()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return null;

var baseDir = AppContext.BaseDirectory;
var arch = RuntimeInformation.ProcessArchitecture;
var rid = arch == Architecture.Arm64 ? "osx-arm64" : "osx-x64";

return Path.Combine(baseDir, "runtimes", rid, "native", "libphonon.dylib");
}

private static string? GetUniversalPath()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return null;

return Path.Combine(AppContext.BaseDirectory, "runtimes", "osx-universal", "native", "libphonon.dylib");
}
}
Empty file modified pack-local.sh
100644 → 100755
Empty file.