Skip to content

Commit

Permalink
Added system to some audio creation calls.
Browse files Browse the repository at this point in the history
Fixed display mode field order.
  • Loading branch information
tomspilman committed Sep 19, 2024
1 parent 77cceb8 commit ceeb88e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions MonoGame.Framework/Platform/Native/Audio.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal static unsafe partial class MGA
#region Buffer

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGA_Buffer_Create", StringMarshalling = StringMarshalling.Utf8)]
public static partial MGA_Buffer* Buffer_Create();
public static partial MGA_Buffer* Buffer_Create(MGA_System* system);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGA_Buffer_Destroy", StringMarshalling = StringMarshalling.Utf8)]
public static partial void Buffer_Destroy(MGA_Buffer* buffer);
Expand Down Expand Up @@ -142,7 +142,7 @@ public static partial void Buffer_InitializeXact(
#region Voice

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGA_Voice_Create", StringMarshalling = StringMarshalling.Utf8)]
public static partial MGA_Voice* Voice_Create();
public static partial MGA_Voice* Voice_Create(MGA_System* system);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGA_Voice_Destroy", StringMarshalling = StringMarshalling.Utf8)]
public static partial void Voice_Destroy(MGA_Voice* voice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed partial class DynamicSoundEffectInstance : SoundEffectInstance
{
private unsafe void PlatformCreate()
{
Voice = MGA.Voice_Create();
Voice = MGA.Voice_Create(SoundEffect.System);
}

private unsafe int PlatformGetPendingBufferCount()
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Native/Graphics.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ [MGHandle] internal readonly struct MGG_OcclusionQuery { }
[StructLayout(LayoutKind.Sequential)]
internal struct MGG_DisplayMode
{
public SurfaceFormat format;
public int width;
public int height;
public SurfaceFormat format;
}

[StructLayout(LayoutKind.Sequential)]
Expand Down
10 changes: 5 additions & 5 deletions MonoGame.Framework/Platform/Native/SoundEffect.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void PlatformLoadAudioStream(Stream s, out TimeSpan duration)

unsafe
{
Buffer = MGA.Buffer_Create();
Buffer = MGA.Buffer_Create(System);
MGA.Buffer_InitializeFormat(Buffer, headerData, waveData, waveData.Length, 0, 0);

var milliseconds = MGA.Buffer_GetDuration(Buffer);
Expand All @@ -80,13 +80,13 @@ private void PlatformLoadAudioStream(Stream s, out TimeSpan duration)

private unsafe void PlatformInitializePcm(byte[] buffer, int offset, int count, int sampleBits, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
{
Buffer = MGA.Buffer_Create();
Buffer = MGA.Buffer_Create(System);
MGA.Buffer_InitializePCM(Buffer, buffer, offset, count, sampleBits, sampleRate, (int)channels, loopStart, loopLength);
}

private unsafe void PlatformInitializeFormat(byte[] header, byte[] buffer, int bufferSize, int loopStart, int loopLength)
{
Buffer = MGA.Buffer_Create();
Buffer = MGA.Buffer_Create(System);
MGA.Buffer_InitializeFormat(Buffer, header, buffer, bufferSize, loopStart, loopLength);
}

Expand All @@ -96,7 +96,7 @@ private unsafe void PlatformInitializeXact(MiniFormatTag codec, byte[] buffer, i
// This is only the platform specific non-streaming
// Xact sound handling as PCM is already handled.

Buffer = MGA.Buffer_Create();
Buffer = MGA.Buffer_Create(System);
MGA.Buffer_InitializeXact(Buffer, (uint)codec, buffer, buffer.Length, sampleRate, blockAlignment, channels, loopStart, loopLength);

var milliseconds = MGA.Buffer_GetDuration(Buffer);
Expand All @@ -109,7 +109,7 @@ private unsafe void PlatformSetupInstance(SoundEffectInstance instance)
// already have a valid voice assigned.

if (instance.Voice == null)
instance.Voice = MGA.Voice_Create();
instance.Voice = MGA.Voice_Create(System);

MGA.Voice_SetBuffer(instance.Voice, Buffer);
}
Expand Down
6 changes: 4 additions & 2 deletions native/monogame/faudio/MGA_faudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ void MGA_System_SetReverbSettings(MGA_System* system, ReverbSettings& settings)
assert(system != nullptr);
}

MGA_Buffer* MGA_Buffer_Create()
MGA_Buffer* MGA_Buffer_Create(MGA_System* system)
{
assert(system != nullptr);
auto buffer = new MGA_Buffer();
return buffer;
}
Expand Down Expand Up @@ -90,8 +91,9 @@ mgulong MGA_Buffer_GetDuration(MGA_Buffer* buffer)
return 0;
}

MGA_Voice* MGA_Voice_Create()
MGA_Voice* MGA_Voice_Create(MGA_System* system)
{
assert(system != nullptr);
auto voice = new MGA_Voice();
return voice;
}
Expand Down
4 changes: 2 additions & 2 deletions native/monogame/include/api_MGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ MG_EXPORT MGA_System* MGA_System_Create();
MG_EXPORT void MGA_System_Destroy(MGA_System* system);
MG_EXPORT mgint MGA_System_GetMaxInstances();
MG_EXPORT void MGA_System_SetReverbSettings(MGA_System* system, ReverbSettings& settings);
MG_EXPORT MGA_Buffer* MGA_Buffer_Create();
MG_EXPORT MGA_Buffer* MGA_Buffer_Create(MGA_System* system);
MG_EXPORT void MGA_Buffer_Destroy(MGA_Buffer* buffer);
MG_EXPORT void MGA_Buffer_InitializeFormat(MGA_Buffer* buffer, mgbyte* waveHeader, mgbyte* waveData, mgint length, mgint loopStart, mgint loopLength);
MG_EXPORT void MGA_Buffer_InitializePCM(MGA_Buffer* buffer, mgbyte* waveData, mgint offset, mgint length, mgint sampleBits, mgint sampleRate, mgint channels, mgint loopStart, mgint loopLength);
MG_EXPORT void MGA_Buffer_InitializeXact(MGA_Buffer* buffer, mguint codec, mgbyte* waveData, mgint length, mgint sampleRate, mgint blockAlignment, mgint channels, mgint loopStart, mgint loopLength);
MG_EXPORT mgulong MGA_Buffer_GetDuration(MGA_Buffer* buffer);
MG_EXPORT MGA_Voice* MGA_Voice_Create();
MG_EXPORT MGA_Voice* MGA_Voice_Create(MGA_System* system);
MG_EXPORT void MGA_Voice_Destroy(MGA_Voice* voice);
MG_EXPORT mgint MGA_Voice_GetBufferCount(MGA_Voice* voice);
MG_EXPORT void MGA_Voice_SetBuffer(MGA_Voice* voice, MGA_Buffer* buffer);
Expand Down
1 change: 1 addition & 0 deletions native/monogame/include/api_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum class MGSurfaceFormat : mgint
Srgb8A1Etc2 = 93,
Rgba8Etc2 = 94,
SRgb8A8Etc2 = 95,
Astc4X4Rgba = 96,
};

enum class MGDepthFormat : mgint
Expand Down

0 comments on commit ceeb88e

Please sign in to comment.