using System;
using NAudio.CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace NAudio.CoreAudioApi
{
///
/// Audio Render Client
///
public class AudioRenderClient : IDisposable
{
IAudioRenderClient audioRenderClientInterface;
internal AudioRenderClient(IAudioRenderClient audioRenderClientInterface)
{
this.audioRenderClientInterface = audioRenderClientInterface;
}
///
/// Gets a pointer to the buffer
///
/// Number of frames requested
/// Pointer to the buffer
public IntPtr GetBuffer(int numFramesRequested)
{
Marshal.ThrowExceptionForHR(audioRenderClientInterface.GetBuffer(numFramesRequested, out var bufferPointer));
return bufferPointer;
}
///
/// Release buffer
///
/// Number of frames written
/// Buffer flags
public void ReleaseBuffer(int numFramesWritten,AudioClientBufferFlags bufferFlags)
{
Marshal.ThrowExceptionForHR(audioRenderClientInterface.ReleaseBuffer(numFramesWritten, bufferFlags));
}
///
/// Release the COM object
///
public void Dispose()
{
if (audioRenderClientInterface != null)
{
// althugh GC would do this for us, we want it done now
// to let us reopen WASAPI
Marshal.ReleaseComObject(audioRenderClientInterface);
audioRenderClientInterface = null;
GC.SuppressFinalize(this);
}
}
}
}