Files
UmaViewer/Assets/Scripts/Audio/NAudio/CoreAudioApi/SimpleAudioVolume.cs
T
2022-09-10 16:59:44 +08:00

90 lines
2.2 KiB
C#

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