add FNA dependency

main
cosmonaut 2022-04-20 13:53:53 -07:00
parent b6bf39e3c9
commit dbfcd15ca2
13 changed files with 48 additions and 50 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
bin
obj
.vs

12
FineAudio.Core.csproj Normal file
View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.Core.csproj" />
</ItemGroup>
</Project>

12
FineAudio.csproj Normal file
View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FNA\FNA.csproj" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class AudioDevice : IDisposable public class AudioDevice : IDisposable
{ {
@ -34,7 +35,7 @@ namespace MoonWorks.Audio
if (devices == 0) if (devices == 0)
{ {
Logger.LogError("No audio devices found!"); FNALoggerEXT.LogError("No audio devices found!");
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
FAudio.FAudio_Release(Handle); FAudio.FAudio_Release(Handle);
return; return;
@ -81,7 +82,7 @@ namespace MoonWorks.Audio
IntPtr.Zero IntPtr.Zero
) != 0) ) != 0)
{ {
Logger.LogError("No mastering voice found!"); FNALoggerEXT.LogError("No mastering voice found!");
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
FAudio.FAudio_Release(Handle); FAudio.FAudio_Release(Handle);
return; return;

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using Microsoft.Xna.Framework;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class AudioEmitter : AudioResource public class AudioEmitter : AudioResource
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using MoonWorks.Math; using Microsoft.Xna.Framework;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class AudioListener : AudioResource public class AudioListener : AudioResource
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace MoonWorks.Audio namespace FineAudio
{ {
public abstract class AudioResource : IDisposable public abstract class AudioResource : IDisposable
{ {

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks.Math; using Microsoft.Xna.Framework;
namespace MoonWorks.Audio namespace FineAudio
{ {
public abstract class SoundInstance : AudioResource public abstract class SoundInstance : AudioResource
{ {
@ -195,7 +195,7 @@ namespace MoonWorks.Audio
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
{ {
Logger.LogError("SoundInstance failed to initialize!"); FNALoggerEXT.LogError("SoundInstance failed to initialize!");
return; return;
} }

View File

@ -1,4 +1,4 @@
namespace MoonWorks.Audio namespace FineAudio
{ {
public enum SoundState public enum SoundState
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class StaticSound : AudioResource public class StaticSound : AudioResource
{ {
@ -19,37 +19,6 @@ namespace MoonWorks.Audio
private Stack<StaticSoundInstance> Instances = new Stack<StaticSoundInstance>(); private Stack<StaticSoundInstance> Instances = new Stack<StaticSoundInstance>();
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 // mostly borrowed from https://github.com/FNA-XNA/FNA/blob/b71b4a35ae59970ff0070dea6f8620856d8d4fec/src/Audio/SoundEffect.cs#L385
public static StaticSound LoadWav(AudioDevice device, string filePath) public static StaticSound LoadWav(AudioDevice device, string filePath)
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class StaticSoundInstance : SoundInstance public class StaticSoundInstance : SoundInstance
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace MoonWorks.Audio namespace FineAudio
{ {
/// <summary> /// <summary>
/// For streaming long playback. /// For streaming long playback.

View File

@ -1,8 +1,9 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
namespace MoonWorks.Audio namespace FineAudio
{ {
public class StreamingSoundOgg : StreamingSound public class StreamingSoundOgg : StreamingSound
{ {
@ -26,9 +27,9 @@ namespace MoonWorks.Audio
if (error != 0) if (error != 0)
{ {
((GCHandle) fileDataPtr).Free(); ((GCHandle) fileDataPtr).Free();
Logger.LogError("Error opening OGG file!"); FNALoggerEXT.LogError("Error opening OGG file!");
Logger.LogError("Error: " + error); FNALoggerEXT.LogError("Error: " + error);
throw new AudioLoadException("Error opening OGG file!"); throw new System.ArgumentException("OGG file not valid!");
} }
var info = FAudio.stb_vorbis_get_info(vorbisHandle); var info = FAudio.stb_vorbis_get_info(vorbisHandle);