Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions RhythmGameUtilities/Scripts/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions UnityPackage/Scripts/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions includes/RhythmGameUtilities/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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