From dbfcd15ca25009f095e15b972d7dc2e3f8473b14 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 20 Apr 2022 13:53:53 -0700 Subject: [PATCH] add FNA dependency --- .gitignore | 3 ++ FineAudio.Core.csproj | 12 +++++++ FineAudio.csproj | 12 +++++++ AudioDevice.cs => src/AudioDevice.cs | 7 ++-- AudioEmitter.cs => src/AudioEmitter.cs | 4 +-- AudioListener.cs => src/AudioListener.cs | 4 +-- AudioResource.cs => src/AudioResource.cs | 2 +- SoundInstance.cs => src/SoundInstance.cs | 6 ++-- SoundState.cs => src/SoundState.cs | 2 +- StaticSound.cs => src/StaticSound.cs | 33 +------------------ .../StaticSoundInstance.cs | 2 +- StreamingSound.cs => src/StreamingSound.cs | 2 +- .../StreamingSoundOgg.cs | 9 ++--- 13 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 .gitignore create mode 100644 FineAudio.Core.csproj create mode 100644 FineAudio.csproj rename AudioDevice.cs => src/AudioDevice.cs (97%) rename AudioEmitter.cs => src/AudioEmitter.cs (98%) rename AudioListener.cs => src/AudioListener.cs (97%) rename AudioResource.cs => src/AudioResource.cs (97%) rename SoundInstance.cs => src/SoundInstance.cs (98%) rename SoundState.cs => src/SoundState.cs (69%) rename StaticSound.cs => src/StaticSound.cs (89%) rename StaticSoundInstance.cs => src/StaticSoundInstance.cs (98%) rename StreamingSound.cs => src/StreamingSound.cs (99%) rename StreamingSoundOgg.cs => src/StreamingSoundOgg.cs (90%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cd48b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin +obj +.vs diff --git a/FineAudio.Core.csproj b/FineAudio.Core.csproj new file mode 100644 index 0000000..914176b --- /dev/null +++ b/FineAudio.Core.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + true + + + + + + + diff --git a/FineAudio.csproj b/FineAudio.csproj new file mode 100644 index 0000000..ee24162 --- /dev/null +++ b/FineAudio.csproj @@ -0,0 +1,12 @@ + + + + net472 + true + + + + + + + diff --git a/AudioDevice.cs b/src/AudioDevice.cs similarity index 97% rename from AudioDevice.cs rename to src/AudioDevice.cs index 9dbb52b..12328b0 100644 --- a/AudioDevice.cs +++ b/src/AudioDevice.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using Microsoft.Xna.Framework; -namespace MoonWorks.Audio +namespace FineAudio { public class AudioDevice : IDisposable { @@ -34,7 +35,7 @@ namespace MoonWorks.Audio if (devices == 0) { - Logger.LogError("No audio devices found!"); + FNALoggerEXT.LogError("No audio devices found!"); Handle = IntPtr.Zero; FAudio.FAudio_Release(Handle); return; @@ -81,7 +82,7 @@ namespace MoonWorks.Audio IntPtr.Zero ) != 0) { - Logger.LogError("No mastering voice found!"); + FNALoggerEXT.LogError("No mastering voice found!"); Handle = IntPtr.Zero; FAudio.FAudio_Release(Handle); return; diff --git a/AudioEmitter.cs b/src/AudioEmitter.cs similarity index 98% rename from AudioEmitter.cs rename to src/AudioEmitter.cs index c23becd..327e6d2 100644 --- a/AudioEmitter.cs +++ b/src/AudioEmitter.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.InteropServices; -using MoonWorks.Math; +using Microsoft.Xna.Framework; -namespace MoonWorks.Audio +namespace FineAudio { public class AudioEmitter : AudioResource { diff --git a/AudioListener.cs b/src/AudioListener.cs similarity index 97% rename from AudioListener.cs rename to src/AudioListener.cs index 0f9e515..35fd131 100644 --- a/AudioListener.cs +++ b/src/AudioListener.cs @@ -1,7 +1,7 @@ using System; -using MoonWorks.Math; +using Microsoft.Xna.Framework; -namespace MoonWorks.Audio +namespace FineAudio { public class AudioListener : AudioResource { diff --git a/AudioResource.cs b/src/AudioResource.cs similarity index 97% rename from AudioResource.cs rename to src/AudioResource.cs index edf8b49..3cf9066 100644 --- a/AudioResource.cs +++ b/src/AudioResource.cs @@ -1,6 +1,6 @@ using System; -namespace MoonWorks.Audio +namespace FineAudio { public abstract class AudioResource : IDisposable { diff --git a/SoundInstance.cs b/src/SoundInstance.cs similarity index 98% rename from SoundInstance.cs rename to src/SoundInstance.cs index 731237e..ee1550f 100644 --- a/SoundInstance.cs +++ b/src/SoundInstance.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.InteropServices; -using MoonWorks.Math; +using Microsoft.Xna.Framework; -namespace MoonWorks.Audio +namespace FineAudio { public abstract class SoundInstance : AudioResource { @@ -195,7 +195,7 @@ namespace MoonWorks.Audio if (Handle == IntPtr.Zero) { - Logger.LogError("SoundInstance failed to initialize!"); + FNALoggerEXT.LogError("SoundInstance failed to initialize!"); return; } diff --git a/SoundState.cs b/src/SoundState.cs similarity index 69% rename from SoundState.cs rename to src/SoundState.cs index 4fb9cb2..e3c7e3e 100644 --- a/SoundState.cs +++ b/src/SoundState.cs @@ -1,4 +1,4 @@ -namespace MoonWorks.Audio +namespace FineAudio { public enum SoundState { diff --git a/StaticSound.cs b/src/StaticSound.cs similarity index 89% rename from StaticSound.cs rename to src/StaticSound.cs index 4976244..d618225 100644 --- a/StaticSound.cs +++ b/src/StaticSound.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; -namespace MoonWorks.Audio +namespace FineAudio { public class StaticSound : AudioResource { @@ -19,37 +19,6 @@ namespace MoonWorks.Audio private Stack Instances = new Stack(); - public static StaticSound LoadOgg(AudioDevice device, string filePath) - { - var filePointer = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero); - - if (error != 0) - { - throw new AudioLoadException("Error loading file!"); - } - var info = FAudio.stb_vorbis_get_info(filePointer); - var bufferSize = FAudio.stb_vorbis_stream_length_in_samples(filePointer) * info.channels; - var buffer = new float[bufferSize]; - - FAudio.stb_vorbis_get_samples_float_interleaved( - filePointer, - info.channels, - buffer, - (int) bufferSize - ); - - FAudio.stb_vorbis_close(filePointer); - - return new StaticSound( - device, - (ushort) info.channels, - info.sample_rate, - buffer, - 0, - (uint) buffer.Length - ); - } - // mostly borrowed from https://github.com/FNA-XNA/FNA/blob/b71b4a35ae59970ff0070dea6f8620856d8d4fec/src/Audio/SoundEffect.cs#L385 public static StaticSound LoadWav(AudioDevice device, string filePath) { diff --git a/StaticSoundInstance.cs b/src/StaticSoundInstance.cs similarity index 98% rename from StaticSoundInstance.cs rename to src/StaticSoundInstance.cs index cb7966a..47fcc48 100644 --- a/StaticSoundInstance.cs +++ b/src/StaticSoundInstance.cs @@ -1,6 +1,6 @@ using System; -namespace MoonWorks.Audio +namespace FineAudio { public class StaticSoundInstance : SoundInstance { diff --git a/StreamingSound.cs b/src/StreamingSound.cs similarity index 99% rename from StreamingSound.cs rename to src/StreamingSound.cs index 18a5a33..48a8c85 100644 --- a/StreamingSound.cs +++ b/src/StreamingSound.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; -namespace MoonWorks.Audio +namespace FineAudio { /// /// For streaming long playback. diff --git a/StreamingSoundOgg.cs b/src/StreamingSoundOgg.cs similarity index 90% rename from StreamingSoundOgg.cs rename to src/StreamingSoundOgg.cs index a83e95a..b11be92 100644 --- a/StreamingSoundOgg.cs +++ b/src/StreamingSoundOgg.cs @@ -1,8 +1,9 @@ using System; using System.IO; using System.Runtime.InteropServices; +using Microsoft.Xna.Framework; -namespace MoonWorks.Audio +namespace FineAudio { public class StreamingSoundOgg : StreamingSound { @@ -26,9 +27,9 @@ namespace MoonWorks.Audio if (error != 0) { ((GCHandle) fileDataPtr).Free(); - Logger.LogError("Error opening OGG file!"); - Logger.LogError("Error: " + error); - throw new AudioLoadException("Error opening OGG file!"); + FNALoggerEXT.LogError("Error opening OGG file!"); + FNALoggerEXT.LogError("Error: " + error); + throw new System.ArgumentException("OGG file not valid!"); } var info = FAudio.stb_vorbis_get_info(vorbisHandle);