Skip to content

Commit 8a1d9f4

Browse files
committed
Added method for freeing the waveform pointer.
1 parent 1de5f97 commit 8a1d9f4

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

RhythmGameUtilities/Scripts/Audio.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ internal static class AudioInternal
1616
#endif
1717
public static extern IntPtr ConvertSamplesToWaveform(float[] samples, int size, int width, int height);
1818

19+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
20+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
21+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
22+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
23+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
24+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
25+
#endif
26+
public static extern void FreeWaveform(IntPtr waveform, int width);
27+
1928
}
2029

2130
public static class Audio
@@ -36,6 +45,8 @@ public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int h
3645
Marshal.Copy(innerPtr, waveform[x], 0, height);
3746
}
3847

48+
AudioInternal.FreeWaveform(ptr, width);
49+
3950
return waveform;
4051
}
4152

UnityPackage/Scripts/Audio.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ internal static class AudioInternal
1616
#endif
1717
public static extern IntPtr ConvertSamplesToWaveform(float[] samples, int size, int width, int height);
1818

19+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
20+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
21+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
22+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
23+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
24+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
25+
#endif
26+
public static extern void FreeWaveform(IntPtr waveform, int width);
27+
1928
}
2029

2130
public static class Audio
@@ -36,6 +45,8 @@ public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int h
3645
Marshal.Copy(innerPtr, waveform[x], 0, height);
3746
}
3847

48+
AudioInternal.FreeWaveform(ptr, width);
49+
3950
return waveform;
4051
}
4152

includes/RhythmGameUtilities/Audio.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ extern "C"
5656

5757
return waveform;
5858
}
59+
60+
PACKAGE_API void FreeWaveform(int **waveform, int width)
61+
{
62+
if (waveform != nullptr)
63+
{
64+
for (int x = 0; x < width; x++)
65+
{
66+
delete[] waveform[x];
67+
}
68+
delete[] waveform;
69+
}
70+
}
5971
}
6072

6173
} // namespace RhythmGameUtilities

0 commit comments

Comments
 (0)