Initial sound impl

This commit is contained in:
2023-08-28 18:38:06 +02:00
parent 06c521a981
commit f4f88f711a
17 changed files with 372 additions and 10 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Numerics;
using Ryuclaw.Shared.Audio;
namespace Ryuclaw.Audio.Desktop
{
public abstract class AbstractAudioSource : IAudioSource
{
private Vector3 _position { get; set; }
public AbstractAudioSource()
{
}
public abstract void Play();
public void SetPosition(Vector3 position)
{
_position = position;
}
public abstract void Stop();
public void Update(float dt)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Ryuclaw.Shared.Audio;
using Ryuclaw.Audio.Shared;
namespace Ryuclaw.Audio.Desktop
{
public class AudioCache : IAudioCache
{
private Dictionary<string, WaveReader> _cache;
public AudioCache()
{
_cache = new();
}
public WaveReader Get(string name)
{
if (_cache.TryGetValue(name, out var reader))
{
return reader;
} else
{
var newReader = new WaveReader();
newReader.Load(name);
_cache[name] = newReader;
return newReader;
}
}
public void Set(string name, IAudioSource source)
{
throw new NotImplementedException();
}
IAudioSource IAudioCache.Get(string name)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using Ryuclaw.Shared.Audio;
using OpenAL;
using System.Numerics;
namespace Ryuclaw.Audio.Desktop;
public class AudioEngine : IAudioEngine
{
private readonly object _lock = new object();
private IntPtr _context;
private IntPtr _device;
private AudioCache _cache;
public AudioEngine()
{
_device = ALC10.alcOpenDevice(null);
_context = ALC10.alcCreateContext(_device, null);
_cache = new AudioCache();
}
public IAudioSource CreateSource(string name)
{
throw new NotImplementedException();
}
public void SetListenerOrientation(Vector3 forward, Vector3 up)
{
throw new NotImplementedException();
}
public void SetListenerPosition(Vector3 position)
{
throw new NotImplementedException();
}
public bool Start()
{
ALC10.alcMakeContextCurrent(_context);
return true;
}
public void Stop()
{
throw new NotImplementedException();
}
public void Update(float dt)
{
throw new NotImplementedException();
}
}

View File

@@ -1,7 +0,0 @@
namespace Ryuclaw.Audio.Desktop;
public class Class1
{
}

View File

@@ -0,0 +1,28 @@
using System;
using Ryuclaw.Audio.Shared;
namespace Ryuclaw.Audio.Desktop
{
public class MemoryAudioSource : AbstractAudioSource
{
private WaveReader _reader;
public MemoryAudioSource(string name)
{
_reader = new WaveReader();
_reader.Load(name);
Console.WriteLine(_reader);
}
public override void Play()
{
throw new NotImplementedException();
}
public override void Stop()
{
throw new NotImplementedException();
}
}
}

View File

@@ -8,5 +8,11 @@
<ItemGroup>
<ProjectReference Include="..\Ryuclaw.Shared\Ryuclaw.Shared.csproj" />
<ProjectReference Include="..\Ryuclaw.Audio.Shared\Ryuclaw.Audio.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="OpenAL-CS">
<HintPath>..\..\..\code\OpenAL-CS\bin\Debug\netstandard2.0\OpenAL-CS.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<dllmap dll="soft_oal.dll" os="windows" target="soft_oal.dll"/>
<dllmap dll="soft_oal.dll" os="osx" target="libopenal.1.23.1.dylib"/>
<dllmap dll="soft_oal.dll" os="linux" target="libopenal.so.1"/>
<dllmap dll="soft_oal.dll" os="ios" target="__internal"/>
</configuration>