2022-02-23 05:14:32 +00:00
|
|
|
|
using System;
|
2021-02-27 00:17:26 +00:00
|
|
|
|
|
|
|
|
|
namespace MoonWorks.Audio
|
|
|
|
|
{
|
2022-02-23 05:14:32 +00:00
|
|
|
|
public abstract class AudioResource : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public AudioDevice Device { get; }
|
|
|
|
|
|
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
|
|
2023-03-07 23:28:57 +00:00
|
|
|
|
internal WeakReference weakReference;
|
2022-02-23 05:14:32 +00:00
|
|
|
|
|
|
|
|
|
public AudioResource(AudioDevice device)
|
|
|
|
|
{
|
|
|
|
|
Device = device;
|
|
|
|
|
|
2023-03-07 23:28:57 +00:00
|
|
|
|
weakReference = new WeakReference(this);
|
|
|
|
|
Device.AddResourceReference(this);
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void Destroy();
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
Destroy();
|
|
|
|
|
|
2023-03-07 23:28:57 +00:00
|
|
|
|
if (weakReference != null)
|
2022-02-23 05:14:32 +00:00
|
|
|
|
{
|
2023-03-07 23:28:57 +00:00
|
|
|
|
Device.RemoveResourceReference(this);
|
|
|
|
|
weakReference = null;
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~AudioResource()
|
|
|
|
|
{
|
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
|
Dispose(disposing: false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-27 00:17:26 +00:00
|
|
|
|
}
|