diff --git a/RhythmGameUtilities/Scripts/Audio.cs b/RhythmGameUtilities/Scripts/Audio.cs index 1e408a8..185fa7c 100644 --- a/RhythmGameUtilities/Scripts/Audio.cs +++ b/RhythmGameUtilities/Scripts/Audio.cs @@ -16,6 +16,15 @@ internal static class AudioInternal #endif public static extern IntPtr ConvertSamplesToWaveform(float[] samples, int size, int width, int height); +#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + [DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)] +#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + [DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)] +#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + [DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)] +#endif + public static extern void FreeWaveform(IntPtr waveform, int width); + } public static class Audio @@ -36,6 +45,8 @@ public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int h Marshal.Copy(innerPtr, waveform[x], 0, height); } + AudioInternal.FreeWaveform(ptr, width); + return waveform; } diff --git a/UnityPackage/Scripts/Audio.cs b/UnityPackage/Scripts/Audio.cs index 1e408a8..185fa7c 100644 --- a/UnityPackage/Scripts/Audio.cs +++ b/UnityPackage/Scripts/Audio.cs @@ -16,6 +16,15 @@ internal static class AudioInternal #endif public static extern IntPtr ConvertSamplesToWaveform(float[] samples, int size, int width, int height); +#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN + [DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)] +#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX + [DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)] +#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX + [DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)] +#endif + public static extern void FreeWaveform(IntPtr waveform, int width); + } public static class Audio @@ -36,6 +45,8 @@ public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int h Marshal.Copy(innerPtr, waveform[x], 0, height); } + AudioInternal.FreeWaveform(ptr, width); + return waveform; } diff --git a/includes/RhythmGameUtilities/Audio.hpp b/includes/RhythmGameUtilities/Audio.hpp index 6d789da..4326f1c 100644 --- a/includes/RhythmGameUtilities/Audio.hpp +++ b/includes/RhythmGameUtilities/Audio.hpp @@ -56,6 +56,18 @@ extern "C" return waveform; } + + PACKAGE_API void FreeWaveform(int **waveform, int width) + { + if (waveform != nullptr) + { + for (int x = 0; x < width; x++) + { + delete[] waveform[x]; + } + delete[] waveform; + } + } } } // namespace RhythmGameUtilities