// -----------------------------------------
// milligan22963 - implemented to work with nAudio
// 12/2014
// -----------------------------------------
using System;
using System.Runtime.InteropServices;
using NAudio.CoreAudioApi.Interfaces;
namespace NAudio.CoreAudioApi
{
///
/// Windows CoreAudio SimpleAudioVolume
///
public class SimpleAudioVolume : IDisposable
{
private readonly ISimpleAudioVolume simpleAudioVolume;
///
/// Creates a new Audio endpoint volume
///
/// ISimpleAudioVolume COM interface
internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume)
{
simpleAudioVolume = realSimpleVolume;
}
#region IDisposable Members
///
/// Dispose
///
public void Dispose()
{
GC.SuppressFinalize(this);
}
///
/// Finalizer
///
~SimpleAudioVolume()
{
Dispose();
}
#endregion
///
/// Allows the user to adjust the volume from
/// 0.0 to 1.0
///
public float Volume
{
get
{
Marshal.ThrowExceptionForHR(simpleAudioVolume.GetMasterVolume(out var result));
return result;
}
set
{
if ((value >= 0.0) && (value <= 1.0))
{
Marshal.ThrowExceptionForHR(simpleAudioVolume.SetMasterVolume(value, Guid.Empty));
}
// should throw something if out of range
}
}
///
/// Mute
///
public bool Mute
{
get
{
Marshal.ThrowExceptionForHR(simpleAudioVolume.GetMute(out var result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(simpleAudioVolume.SetMute(value, Guid.Empty));
}
}
}
}