Skip to content

Commit a554d79

Browse files
authored
Add OpenAL Soft native libraries (#483)
* OpenAL: Add OpenAL-Soft native libraries * OpenAL: Add soft parameter to GetApi. Update version. * OpenAL: Add Soft to package names, cache soft and search paths in AL. * openal: remove package id from project file
1 parent 302701d commit a554d79

File tree

11 files changed

+116
-4
lines changed

11 files changed

+116
-4
lines changed

Silk.NET.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WavePlayer", "examples\CSha
392392
EndProject
393393
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImGuiVulkan", "src\Lab\Experiments\ImGuiVulkan\ImGuiVulkan.csproj", "{89B03DDB-EBCA-4E6A-80AB-9FFD48110097}"
394394
EndProject
395+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenAL.Soft.Native", "src\Native\Silk.NET.OpenAL.Soft.Native\Silk.NET.OpenAL.Soft.Native.csproj", "{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}"
396+
EndProject
395397
Global
396398
GlobalSection(SolutionConfigurationPlatforms) = preSolution
397399
Debug|Any CPU = Debug|Any CPU
@@ -2297,6 +2299,18 @@ Global
22972299
{89B03DDB-EBCA-4E6A-80AB-9FFD48110097}.Release|x64.Build.0 = Release|Any CPU
22982300
{89B03DDB-EBCA-4E6A-80AB-9FFD48110097}.Release|x86.ActiveCfg = Release|Any CPU
22992301
{89B03DDB-EBCA-4E6A-80AB-9FFD48110097}.Release|x86.Build.0 = Release|Any CPU
2302+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2303+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|Any CPU.Build.0 = Debug|Any CPU
2304+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|x64.ActiveCfg = Debug|Any CPU
2305+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|x64.Build.0 = Debug|Any CPU
2306+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|x86.ActiveCfg = Debug|Any CPU
2307+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Debug|x86.Build.0 = Debug|Any CPU
2308+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|Any CPU.ActiveCfg = Release|Any CPU
2309+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|Any CPU.Build.0 = Release|Any CPU
2310+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|x64.ActiveCfg = Release|Any CPU
2311+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|x64.Build.0 = Release|Any CPU
2312+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|x86.ActiveCfg = Release|Any CPU
2313+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B}.Release|x86.Build.0 = Release|Any CPU
23002314
EndGlobalSection
23012315
GlobalSection(SolutionProperties) = preSolution
23022316
HideSolutionNode = FALSE
@@ -2474,6 +2488,7 @@ Global
24742488
{235C692C-AD31-443F-872F-BD57E75830C4} = {6842A2C6-5C7B-42DD-9825-0EDE91BFEBF7}
24752489
{43896917-9904-4AE7-B634-32850471789F} = {235C692C-AD31-443F-872F-BD57E75830C4}
24762490
{89B03DDB-EBCA-4E6A-80AB-9FFD48110097} = {39B598E9-44BA-4A61-A1BB-7C543734DBA6}
2491+
{0DF430D1-39E6-46F5-AE58-B6DE0BD3F72B} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
24772492
EndGlobalSection
24782493
GlobalSection(ExtensibilityGlobals) = postSolution
24792494
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}

src/Native/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ compatibility with the rest of your solution:
1515

1616
- Silk.NET.Assimp.Native: BSD-3-Clause
1717
- Silk.NET.SDL.Native and Silk.NET.GLFW.Native: Zlib
18+
- Silk.NET.OpenAL.Soft.Native: LGPL-2.0-or-later
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<SilkSourceLinkExempt>true</SilkSourceLinkExempt>
5+
</PropertyGroup>
6+
7+
<Import Project="..\..\..\build\props\common.props" />
8+
9+
<PropertyGroup>
10+
<TargetFrameworks>netstandard2.0;net4.6.1</TargetFrameworks>
11+
<PackageVersion>1.21.1</PackageVersion>
12+
<Authors>.NET Foundation and Contributors</Authors>
13+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14+
<PackageLicenseExpression>LGPL-2.0-or-later</PackageLicenseExpression>
15+
<PackageProjectUrl>https://github.com/dotnet/Silk.NET</PackageProjectUrl>
16+
<Description>Multi-platform native library for OpenAL Soft.</Description>
17+
<RepositoryType>git</RepositoryType>
18+
<RepositoryUrl>https://github.com/kcat/openal-soft</RepositoryUrl>
19+
<IncludeBuildOutput>false</IncludeBuildOutput>
20+
<IncludeContentInPack>true</IncludeContentInPack>
21+
</PropertyGroup>
22+
23+
<ItemGroup>
24+
<Content Include="build\net461\$(PackageId).props" PackagePath="build\net461\$(PackageId).props" />
25+
<Content Include="runtimes\linux-x64\native\libopenal.so" PackagePath="runtimes\linux-x64\native\libopenal.so" />
26+
<Content Include="runtimes\osx-x64\native\libopenal.dylib" PackagePath="runtimes\osx-x64\native\libopenal.dylib" />
27+
<Content Include="runtimes\win-x64\native\soft_oal.dll" PackagePath="runtimes\win-x64\native\soft_oal.dll" />
28+
<Content Include="runtimes\win-x86\native\soft_oal.dll" PackagePath="runtimes\win-x86\native\soft_oal.dll" />
29+
</ItemGroup>
30+
31+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_Silk_NET_NativePackages_OpenAL_Soft_IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</_Silk_NET_NativePackages_OpenAL_Soft_IsWindows>
5+
<_Silk_NET_NativePackages_OpenAL_Soft_IsMacOS Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</_Silk_NET_NativePackages_OpenAL_Soft_IsMacOS>
6+
<_Silk_NET_NativePackages_OpenAL_Soft_IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</_Silk_NET_NativePackages_OpenAL_Soft_IsLinux>
7+
8+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime Condition=" '$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == '' And '$(_Silk_NET_NativePackages_OpenAL_Soft_IsMacOS)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">osx-x64</_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime>
9+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime Condition=" '$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == '' And '$(_Silk_NET_NativePackages_OpenAL_Soft_IsLinux)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">linux-x64</_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime>
10+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime Condition=" '$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == '' And '$(_Silk_NET_NativePackages_OpenAL_Soft_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'true' Or '$(PlatformTarget)' == 'x86')">win-x86</_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime>
11+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime Condition=" '$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == '' And '$(_Silk_NET_NativePackages_OpenAL_Soft_IsWindows)' == 'true' And ('$(Prefer32Bit)' == 'false' Or '$(PlatformTarget)' == 'x64')">win-x64</_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime>
12+
13+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName Condition="'$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == 'win-x86'">soft_oal.dll</_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName>
14+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName Condition="'$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == 'win-x64'">soft_oal.dll</_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName>
15+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName Condition="'$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == 'osx-x64'">libopenal.dylib</_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName>
16+
<_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName Condition="'$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' == 'linux-x64'">libopenal.so</_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<Content Condition="'$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)' != ''" Include="$(MSBuildThisFileDirectory)..\..\runtimes\$(_Silk_NET_NativePackages_OpenAL_Soft_NativeRuntime)\native\$(_Silk_NET_NativePackages_OpenAL_Soft_NativeLibName)">
20+
<Link>%(Filename)%(Extension)</Link>
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
<Visible>False</Visible>
23+
</Content>
24+
</ItemGroup>
25+
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/OpenAL/Silk.NET.OpenAL/AL/AL.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ namespace Silk.NET.OpenAL
1717
[NativeApi(Prefix = "al")]
1818
public partial class AL : NativeAPI
1919
{
20+
private bool _soft;
21+
private SearchPathContainer? _searchPaths;
22+
2023
/// <inheritdoc cref="NativeLibraryBase" />
2124
protected AL(INativeContext ctx)
2225
: base(ctx)
@@ -27,7 +30,8 @@ protected AL(INativeContext ctx)
2730
public override partial bool IsExtensionPresent(string name);
2831

2932
/// <inheritdoc />
30-
public SearchPathContainer SearchPaths { get; } = new OpenALLibraryNameContainer();
33+
public SearchPathContainer SearchPaths => _searchPaths ??= (_soft
34+
? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer());
3135

3236
/// <inheritdoc />
3337
public partial nint GetProcAddress(string name);
@@ -330,12 +334,17 @@ public partial void GetSourceProperty(uint source, GetSourceInteger param, out i
330334
/// <summary>
331335
/// Gets an instance of the API.
332336
/// </summary>
337+
/// <param name="soft">Use OpenAL Soft libraries.</param>
333338
/// <returns>The instance.</returns>
334-
public static AL GetApi()
339+
public static AL GetApi(bool soft = false)
335340
{
341+
SearchPathContainer searchPaths = soft ? new OpenALSoftLibraryNameContainer() : new OpenALLibraryNameContainer();
336342
var ctx = new MultiNativeContext
337-
(CreateDefaultContext(new OpenALLibraryNameContainer().GetLibraryName()), null);
343+
(CreateDefaultContext(searchPaths.GetLibraryName()), null);
338344
var ret = new AL(ctx);
345+
ret._soft = soft;
346+
ret._searchPaths = searchPaths;
347+
339348
ctx.Contexts[1] = new LamdaNativeContext
340349
(x => x.EndsWith("GetProcAddress") ? default : ret.GetProcAddress(x));
341350
return ret;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.Core.Loader;
5+
6+
namespace Silk.NET.OpenAL
7+
{
8+
/// <summary>
9+
/// Contains the library name of OpenAL.
10+
/// </summary>
11+
internal class OpenALSoftLibraryNameContainer : SearchPathContainer
12+
{
13+
/// <inheritdoc />
14+
public override string Linux => "libopenal.so";
15+
16+
/// <inheritdoc />
17+
public override string MacOS => "libopenal.dylib";
18+
19+
/// <inheritdoc />
20+
public override string Android => Linux;
21+
22+
/// <inheritdoc />
23+
public override string IOS => MacOS;
24+
25+
/// <inheritdoc />
26+
public override string Windows86 => "soft_oal.dll";
27+
28+
/// <inheritdoc />
29+
public override string Windows64 => "soft_oal.dll";
30+
}
31+
}

0 commit comments

Comments
 (0)