2012-02-12 13:00:17 +00:00
|
|
|
|
using System;
|
2011-11-15 19:16:05 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2012-08-22 14:28:22 +00:00
|
|
|
|
using ANX.Framework.NonXNA;
|
2012-08-29 13:04:22 +00:00
|
|
|
|
using ANX.Framework.NonXNA.Development;
|
2012-09-30 11:14:44 +00:00
|
|
|
|
using ANX.Framework.NonXNA.SoundSystem;
|
2011-11-15 19:16:05 +00:00
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-11-15 19:16:05 +00:00
|
|
|
|
|
|
|
|
|
namespace ANX.Framework.Audio
|
|
|
|
|
{
|
2012-09-30 11:14:44 +00:00
|
|
|
|
[PercentageComplete(100)]
|
|
|
|
|
[Developer("AstrorEnales")]
|
|
|
|
|
[TestState(TestStateAttribute.TestState.Untested)]
|
2012-02-12 13:00:17 +00:00
|
|
|
|
public sealed class Microphone
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
#region Private
|
2012-09-30 11:14:44 +00:00
|
|
|
|
private static readonly int defaultMicrophone;
|
|
|
|
|
private IMicrophone nativeMicrophone;
|
2012-08-22 14:28:22 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2012-02-12 13:00:17 +00:00
|
|
|
|
#region Events
|
|
|
|
|
public event EventHandler<EventArgs> BufferReady;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public static ReadOnlyCollection<Microphone> All { get; private set; }
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public static Microphone Default
|
|
|
|
|
{
|
|
|
|
|
get { return All[defaultMicrophone]; }
|
|
|
|
|
}
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public readonly string Name;
|
2012-08-22 14:28:22 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public TimeSpan BufferDuration
|
|
|
|
|
{
|
|
|
|
|
get { return nativeMicrophone.BufferDuration; }
|
|
|
|
|
set { nativeMicrophone.BufferDuration = value; }
|
|
|
|
|
}
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public bool IsHeadset
|
|
|
|
|
{
|
|
|
|
|
get { return nativeMicrophone.IsHeadset; }
|
|
|
|
|
}
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public int SampleRate
|
|
|
|
|
{
|
|
|
|
|
get { return nativeMicrophone.SampleRate; }
|
|
|
|
|
}
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
2012-09-30 11:14:44 +00:00
|
|
|
|
public MicrophoneState State
|
|
|
|
|
{
|
|
|
|
|
get { return nativeMicrophone.State; }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2012-02-12 13:00:17 +00:00
|
|
|
|
|
|
|
|
|
#region Constructor
|
2012-08-22 14:28:22 +00:00
|
|
|
|
static Microphone()
|
|
|
|
|
{
|
|
|
|
|
var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
|
2012-09-30 11:14:44 +00:00
|
|
|
|
All = creator.GetAllMicrophones();
|
|
|
|
|
defaultMicrophone = creator.GetDefaultMicrophone(All);
|
2012-08-22 14:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Microphone(string setName)
|
|
|
|
|
{
|
|
|
|
|
Name = setName;
|
|
|
|
|
var creator = AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>();
|
|
|
|
|
nativeMicrophone = creator.CreateMicrophone(this);
|
2012-09-30 11:14:44 +00:00
|
|
|
|
nativeMicrophone.BufferReady += BufferReady;
|
2012-08-22 14:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-12 13:00:17 +00:00
|
|
|
|
~Microphone()
|
|
|
|
|
{
|
2012-09-30 11:14:44 +00:00
|
|
|
|
if (nativeMicrophone == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nativeMicrophone.BufferReady -= BufferReady;
|
|
|
|
|
nativeMicrophone.Dispose();
|
|
|
|
|
nativeMicrophone = null;
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Stop
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
nativeMicrophone.Stop();
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Start
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
nativeMicrophone.Start();
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region GetSampleSizeInBytes
|
|
|
|
|
public int GetSampleSizeInBytes(TimeSpan duration)
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
return nativeMicrophone.GetSampleSizeInBytes(ref duration);
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region GetSampleDuration
|
|
|
|
|
public TimeSpan GetSampleDuration(int sizeInBytes)
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
return nativeMicrophone.GetSampleDuration(sizeInBytes);
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region GetData
|
|
|
|
|
public int GetData(byte[] buffer)
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
return nativeMicrophone.GetData(buffer);
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetData(byte[] buffer, int offset, int count)
|
|
|
|
|
{
|
2012-08-22 14:28:22 +00:00
|
|
|
|
return nativeMicrophone.GetData(buffer, offset, count);
|
2012-02-12 13:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2011-11-15 19:16:05 +00:00
|
|
|
|
}
|