Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chaifoxes committed Nov 21, 2024
2 parents 2b998bd + e33a4fa commit 832353c
Show file tree
Hide file tree
Showing 67 changed files with 211 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ indent_style = tab

# Code files
[*.*]
indent_size = 2
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## [Unreleased]

### Added:

- Added an option to load from stream or from byte buffer for `LoadSound`, `LoadStreamedSound` and `LoadBank`.

### Changed:

- Made constructors for `Attributes3D`, `Bank`, `Bus`, `EventDescription`, `EventInstance`, `VCA`, `Channel`, `Sound` public instead of internal.
- Updated to FMOD 2.02.25
- Migrated to NET8.

## [v3.1.0] - *04.12.2023*

### Added:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<TargetFramework>net8.0-android</TargetFramework>
<SupportedOSPlatformVersion>23</SupportedOSPlatformVersion>
<DefineConstants>ANDROID;UNITY_2017_4_OR_NEWER;UNITY_PS4</DefineConstants>
<PackageTags>Monogame, FMOD, Audio, Music, Android, ChaiFoxes.FMODAudio</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageOutputPath>..\..\package\</PackageOutputPath>
<OutputPath>..\..\bin\$(Configuration)</OutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\Icon\icon.png">
Expand All @@ -18,6 +19,10 @@
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<Content Include="..\FmodForFoxes\README.md">
<PackagePath>\</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.Android" Version="3.8.1.*" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<NoWarn>1591;1573</NoWarn>
<DefineConstants>UNITY_2017_4_OR_NEWER</DefineConstants>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
Expand All @@ -10,6 +10,7 @@
<PackageOutputPath>..\..\package\</PackageOutputPath>
<OutputPath>..\..\bin\$(Configuration)</OutputPath>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,6 +25,10 @@
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<Content Include="..\FmodForFoxes\README.md">
<PackagePath>\</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.*">
Expand Down
11 changes: 11 additions & 0 deletions FmodForFoxes/FmodForFoxes.Desktop/FmodForFoxes.Desktop.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions FmodForFoxes/FmodForFoxes/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public uint TrackPosition

public FMOD.TIMEUNIT TrackPositionTimeunit;

internal Channel(Sound sound, FMOD.Channel channel)
public Channel(Sound sound, FMOD.Channel channel)
: this(channel)
{
Loops = Sound.Loops;
Expand All @@ -409,7 +409,7 @@ internal Channel(Sound sound, FMOD.Channel channel)
Velocity3D = sound.Velocity3D;
}

internal Channel(FMOD.Channel channel)
public Channel(FMOD.Channel channel)
{
Native = channel;
TrackPositionTimeunit = FMOD.TIMEUNIT.MS;
Expand Down
52 changes: 44 additions & 8 deletions FmodForFoxes/FmodForFoxes/CoreSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,34 @@ public static class CoreSystem
public static Sound LoadSound(string path)
{
var buffer = FileLoader.LoadFileAsBuffer(path);
return LoadSound(buffer);
}

/// <summary>
/// Loads sound from stream.
/// Use this function to load short sound effects.
/// </summary>
public static Sound LoadSound(Stream stream)
{
var buffer = FileLoader.LoadFileAsBuffer(stream);
return LoadSound(buffer);
}

/// <summary>
/// Loads sound from a buffer.
/// Use this function to load short sound effects.
/// </summary>
public static Sound LoadSound(byte[] buffer)
{
var info = new FMOD.CREATESOUNDEXINFO();
info.length = (uint)buffer.Length;
info.cbsize = Marshal.SizeOf(info);

Native.createSound(
buffer,
FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESAMPLE,
ref info,
out FMOD.Sound newSound
buffer,
FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESAMPLE,
ref info,
out FMOD.Sound newSound
);

return new Sound(newSound);
Expand All @@ -45,7 +63,25 @@ out FMOD.Sound newSound
public static Sound LoadStreamedSound(string path)
{
var buffer = FileLoader.LoadFileAsBuffer(path);
return LoadStreamedSound(buffer);
}

/// <summary>
/// Loads streamed sound stream from file.
/// Use this function to load music and long ambience tracks.
/// </summary>
public static Sound LoadStreamedSound(Stream stream)
{
var buffer = FileLoader.LoadFileAsBuffer(stream);
return LoadStreamedSound(buffer);
}

/// <summary>
/// Loads streamed sound stream from file.
/// Use this function to load music and long ambience tracks.
/// </summary>
public static Sound LoadStreamedSound(byte[] buffer)
{
// Internal FMOD pointer points to this memory, so we don't want it to go anywhere.
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

Expand All @@ -54,10 +90,10 @@ public static Sound LoadStreamedSound(string path)
info.cbsize = Marshal.SizeOf(info);

Native.createStream(
buffer,
FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESTREAM,
ref info,
out FMOD.Sound newSound
buffer,
FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESTREAM,
ref info,
out FMOD.Sound newSound
);

return new Sound(newSound, buffer, handle);
Expand Down
10 changes: 5 additions & 5 deletions FmodForFoxes/FmodForFoxes/FMOD/Studio/fmod_studio.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ======================================================================================== */
/* ======================================================================================== */
/* FMOD Studio API - C# wrapper. */
/* Copyright (c), Firelight Technologies Pty, Ltd. 2004-2023. */
/* Copyright (c), Firelight Technologies Pty, Ltd. 2004-2024. */
/* */
/* For more detail visit: */
/* https://fmod.com/docs/2.02/api/studio-api.html */
Expand Down Expand Up @@ -395,7 +395,7 @@ public static RESULT create(out System system)
}
public RESULT setAdvancedSettings(ADVANCEDSETTINGS settings)
{
settings.cbsize = MarshalHelper.SizeOf(typeof(ADVANCEDSETTINGS));
settings.cbsize = Marshal.SizeOf<ADVANCEDSETTINGS>();
return FMOD_Studio_System_SetAdvancedSettings(this.handle, ref settings);
}
public RESULT setAdvancedSettings(ADVANCEDSETTINGS settings, string encryptionKey)
Expand All @@ -411,7 +411,7 @@ public RESULT setAdvancedSettings(ADVANCEDSETTINGS settings, string encryptionKe
}
public RESULT getAdvancedSettings(out ADVANCEDSETTINGS settings)
{
settings.cbsize = MarshalHelper.SizeOf(typeof(ADVANCEDSETTINGS));
settings.cbsize = Marshal.SizeOf<ADVANCEDSETTINGS>();
return FMOD_Studio_System_GetAdvancedSettings(this.handle, out settings);
}
public RESULT initialize(int maxchannels, INITFLAGS studioflags, FMOD.INITFLAGS flags, IntPtr extradriverdata)
Expand Down Expand Up @@ -679,7 +679,7 @@ public RESULT loadBankMemory(byte[] buffer, LOAD_BANK_FLAGS flags, out Bank bank
}
public RESULT loadBankCustom(BANK_INFO info, LOAD_BANK_FLAGS flags, out Bank bank)
{
info.size = MarshalHelper.SizeOf(typeof(BANK_INFO));
info.size = Marshal.SizeOf<BANK_INFO>();
return FMOD_Studio_System_LoadBankCustom(this.handle, ref info, flags, out bank.handle);
}
public RESULT unloadAll()
Expand Down
52 changes: 18 additions & 34 deletions FmodForFoxes/FmodForFoxes/FMOD/fmod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ======================================================================================== */
/* ======================================================================================== */
/* FMOD Core API - C# wrapper. */
/* Copyright (c), Firelight Technologies Pty, Ltd. 2004-2023. */
/* Copyright (c), Firelight Technologies Pty, Ltd. 2004-2024. */
/* */
/* For more detail visit: */
/* https://fmod.com/docs/2.02/api/core-api.html */
Expand All @@ -19,7 +19,7 @@ namespace FMOD
*/
public partial class VERSION
{
public const int number = 0x00020219;
public const int number = 0x00020225;
#if !UNITY_2019_4_OR_NEWER
public const string dll = "fmod";
#endif
Expand Down Expand Up @@ -701,47 +701,47 @@ public struct CREATESOUNDEXINFO
public SOUND_PCMREAD_CALLBACK pcmreadcallback
{
set { pcmreadcallback_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return pcmreadcallback_internal == IntPtr.Zero ? null : (SOUND_PCMREAD_CALLBACK)Marshal.GetDelegateForFunctionPointer(pcmreadcallback_internal, typeof(SOUND_PCMREAD_CALLBACK)); }
get { return pcmreadcallback_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<SOUND_PCMREAD_CALLBACK>(pcmreadcallback_internal); }
}
public SOUND_PCMSETPOS_CALLBACK pcmsetposcallback
{
set { pcmsetposcallback_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return pcmsetposcallback_internal == IntPtr.Zero ? null : (SOUND_PCMSETPOS_CALLBACK)Marshal.GetDelegateForFunctionPointer(pcmsetposcallback_internal, typeof(SOUND_PCMSETPOS_CALLBACK)); }
get { return pcmsetposcallback_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<SOUND_PCMSETPOS_CALLBACK>(pcmsetposcallback_internal); }
}
public SOUND_NONBLOCK_CALLBACK nonblockcallback
{
set { nonblockcallback_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return nonblockcallback_internal == IntPtr.Zero ? null : (SOUND_NONBLOCK_CALLBACK)Marshal.GetDelegateForFunctionPointer(nonblockcallback_internal, typeof(SOUND_NONBLOCK_CALLBACK)); }
get { return nonblockcallback_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<SOUND_NONBLOCK_CALLBACK>(nonblockcallback_internal); }
}
public FILE_OPEN_CALLBACK fileuseropen
{
set { fileuseropen_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuseropen_internal == IntPtr.Zero ? null : (FILE_OPEN_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuseropen_internal, typeof(FILE_OPEN_CALLBACK)); }
get { return fileuseropen_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_OPEN_CALLBACK>(fileuseropen_internal); }
}
public FILE_CLOSE_CALLBACK fileuserclose
{
set { fileuserclose_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuserclose_internal == IntPtr.Zero ? null : (FILE_CLOSE_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuserclose_internal, typeof(FILE_CLOSE_CALLBACK)); }
get { return fileuserclose_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_CLOSE_CALLBACK>(fileuserclose_internal); }
}
public FILE_READ_CALLBACK fileuserread
{
set { fileuserread_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuserread_internal == IntPtr.Zero ? null : (FILE_READ_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuserread_internal, typeof(FILE_READ_CALLBACK)); }
get { return fileuserread_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_READ_CALLBACK>(fileuserread_internal); }
}
public FILE_SEEK_CALLBACK fileuserseek
{
set { fileuserseek_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuserseek_internal == IntPtr.Zero ? null : (FILE_SEEK_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuserseek_internal, typeof(FILE_SEEK_CALLBACK)); }
get { return fileuserseek_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_SEEK_CALLBACK>(fileuserseek_internal); }
}
public FILE_ASYNCREAD_CALLBACK fileuserasyncread
{
set { fileuserasyncread_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuserasyncread_internal == IntPtr.Zero ? null : (FILE_ASYNCREAD_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuserasyncread_internal, typeof(FILE_ASYNCREAD_CALLBACK)); }
get { return fileuserasyncread_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_ASYNCREAD_CALLBACK>(fileuserasyncread_internal); }
}
public FILE_ASYNCCANCEL_CALLBACK fileuserasynccancel
{
set { fileuserasynccancel_internal = (value == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(value)); }
get { return fileuserasynccancel_internal == IntPtr.Zero ? null : (FILE_ASYNCCANCEL_CALLBACK)Marshal.GetDelegateForFunctionPointer(fileuserasynccancel_internal, typeof(FILE_ASYNCCANCEL_CALLBACK)); }
get { return fileuserasynccancel_internal == IntPtr.Zero ? null : Marshal.GetDelegateForFunctionPointer<FILE_ASYNCCANCEL_CALLBACK>(fileuserasynccancel_internal); }
}

}
Expand Down Expand Up @@ -838,6 +838,7 @@ public struct ADVANCEDSETTINGS
public uint randomSeed;
public int maxConvolutionThreads;
public int maxOpusCodecs;
public int maxSpatialObjects;
}

[Flags]
Expand Down Expand Up @@ -1113,12 +1114,12 @@ public RESULT attachFileSystem(FILE_OPEN_CALLBACK useropen, FILE_CLOSE_CALLBACK
}
public RESULT setAdvancedSettings(ref ADVANCEDSETTINGS settings)
{
settings.cbSize = MarshalHelper.SizeOf(typeof(ADVANCEDSETTINGS));
settings.cbSize = Marshal.SizeOf<ADVANCEDSETTINGS>();
return FMOD5_System_SetAdvancedSettings(this.handle, ref settings);
}
public RESULT getAdvancedSettings(ref ADVANCEDSETTINGS settings)
{
settings.cbSize = MarshalHelper.SizeOf(typeof(ADVANCEDSETTINGS));
settings.cbSize = Marshal.SizeOf<ADVANCEDSETTINGS>();
return FMOD5_System_GetAdvancedSettings(this.handle, ref settings);
}
public RESULT setCallback(SYSTEM_CALLBACK callback, SYSTEM_CALLBACK_TYPE callbackmask = SYSTEM_CALLBACK_TYPE.ALL)
Expand Down Expand Up @@ -1320,7 +1321,7 @@ public RESULT createSound(IntPtr name_or_data, MODE mode, ref CREATESOUNDEXINFO
public RESULT createSound(string name, MODE mode, out Sound sound)
{
CREATESOUNDEXINFO exinfo = new CREATESOUNDEXINFO();
exinfo.cbsize = MarshalHelper.SizeOf(typeof(CREATESOUNDEXINFO));
exinfo.cbsize = Marshal.SizeOf<CREATESOUNDEXINFO>();

return createSound(name, mode, ref exinfo, out sound);
}
Expand All @@ -1342,7 +1343,7 @@ public RESULT createStream(IntPtr name_or_data, MODE mode, ref CREATESOUNDEXINFO
public RESULT createStream(string name, MODE mode, out Sound sound)
{
CREATESOUNDEXINFO exinfo = new CREATESOUNDEXINFO();
exinfo.cbsize = MarshalHelper.SizeOf(typeof(CREATESOUNDEXINFO));
exinfo.cbsize = Marshal.SizeOf<CREATESOUNDEXINFO>();

return createStream(name, mode, ref exinfo, out sound);
}
Expand Down Expand Up @@ -3384,7 +3385,7 @@ public RESULT getParameterInfo(int index, out DSP_PARAMETER_DESC desc)
{
IntPtr descPtr;
RESULT result = FMOD5_DSP_GetParameterInfo(this.handle, index, out descPtr);
desc = (DSP_PARAMETER_DESC)MarshalHelper.PtrToStructure(descPtr, typeof(DSP_PARAMETER_DESC));
desc = (DSP_PARAMETER_DESC)Marshal.PtrToStructure<DSP_PARAMETER_DESC>(descPtr);
return result;
}
public RESULT getDataParameterIndex(int datatype, out int index)
Expand Down Expand Up @@ -4062,22 +4063,5 @@ public static ThreadSafeEncoding GetFreeHelper()
}
}

// Some of the Marshal functions were marked as deprecated / obsolete, however that decision was reversed: https://github.com/dotnet/corefx/pull/10541
// Use the old syntax (non-generic) to ensure maximum compatibility (especially with Unity) ignoring the warnings
public static class MarshalHelper
{
#pragma warning disable 618
public static int SizeOf(Type t)
{
return Marshal.SizeOf(t); // Always use Type version, never Object version as it boxes causes GC allocations
}

public static object PtrToStructure(IntPtr ptr, Type structureType)
{
return Marshal.PtrToStructure(ptr, structureType);
}
#pragma warning restore 618
}

#endregion
}
Loading

0 comments on commit 832353c

Please sign in to comment.