-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32a52f0
commit 58b1f03
Showing
5 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Zen.System.Modules.Audio.Engines; | ||
|
||
public interface IZenAudioEngine : IDisposable | ||
{ | ||
void Send(float[] data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Runtime.InteropServices; | ||
using Bufdio; | ||
using Bufdio.Engines; | ||
using Zen.Common.Infrastructure; | ||
|
||
namespace Zen.System.Modules.Audio.Engines; | ||
|
||
public class PortAudioEngine : IZenAudioEngine | ||
{ | ||
private readonly IAudioEngine? _engine; | ||
|
||
public PortAudioEngine() | ||
{ | ||
try | ||
{ | ||
if (Environment.OSVersion.Platform == PlatformID.Unix) | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
BufdioLib.InitializePortAudio(); | ||
} | ||
else | ||
{ | ||
BufdioLib.InitializePortAudio(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Libraries", "libportaudio.dylib")); | ||
} | ||
} | ||
else | ||
{ | ||
BufdioLib.InitializePortAudio(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Libraries", "libportaudio")); | ||
} | ||
|
||
_engine = new Bufdio.Engines.PortAudioEngine(new AudioEngineOptions(1, Constants.SampleRate)); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Logger.LogException(nameof(PortAudioEngine), exception); | ||
} | ||
} | ||
|
||
public void Send(float[] data) | ||
{ | ||
_engine?.Send(data); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_engine?.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters