本文整理汇总了C#中AudioClientShareMode类的典型用法代码示例。如果您正苦于以下问题:C# AudioClientShareMode类的具体用法?C# AudioClientShareMode怎么用?C# AudioClientShareMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AudioClientShareMode类属于命名空间,在下文中一共展示了AudioClientShareMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WasapiOut
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="useEventSync">true if sync is done with event. false use sleep.</param>
/// <param name="latency"></param>
public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)
{
audioClient = device.AudioClient;
this.shareMode = shareMode;
isUsingEventSync = useEventSync;
latencyMilliseconds = latency;
}
示例2: WasapiOutRT
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="latency"></param>
public WasapiOutRT(string device, AudioClientShareMode shareMode, int latency)
{
this.device = device;
this.shareMode = shareMode;
this.latencyMilliseconds = latency;
this.syncContext = SynchronizationContext.Current;
}
示例3: WasapiOut
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="useEventSync">true if sync is done with event. false use sleep.</param>
/// <param name="latency"></param>
public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)
{
this.audioClient = device.AudioClient;
this.shareMode = shareMode;
this.isUsingEventSync = useEventSync;
this.latencyMilliseconds = latency;
this.syncContext = SynchronizationContext.Current;
}
示例4: WasapiOutRT
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="latency"></param>
public WasapiOutRT(string device, AudioClientShareMode shareMode, int latency)
{
this.device = device;
this.shareMode = shareMode;
this.latencyMilliseconds = latency;
this.syncContext = SynchronizationContext.Current;
playThreadEvent = new AutoResetEvent(false);
}
示例5: WasapiOut
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="useEventSync">true if sync is done with event. false use sleep.</param>
/// <param name="latency">Desired latency in milliseconds</param>
public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency)
{
audioClient = device.AudioClient;
mmDevice = device;
this.shareMode = shareMode;
isUsingEventSync = useEventSync;
latencyMilliseconds = latency;
syncContext = SynchronizationContext.Current;
outputFormat = audioClient.MixFormat; // allow the user to query the default format for shared mode streams
}
示例6: WasapiOutGuiThread
/// <summary>
/// Creates a new WASAPI Output device
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode">Share mode to use</param>
/// <param name="latency">Latency in milliseconds</param>
public WasapiOutGuiThread(MMDevice device, AudioClientShareMode shareMode, int latency)
{
audioClient = device.AudioClient;
outputFormat = audioClient.MixFormat;
this.shareMode = shareMode;
latencyMilliseconds = latency;
timer = new Timer();
timer.Tick += TimerOnTick;
timer.Interval = latency/2;
}
示例7: Initialize
/// <summary>
/// Initialize the Audio Client
/// </summary>
/// <param name="shareMode">Share Mode</param>
/// <param name="streamFlags">Stream Flags</param>
/// <param name="bufferDuration">Buffer Duration</param>
/// <param name="periodicity">Periodicity</param>
/// <param name="waveFormat">Wave Format</param>
/// <param name="audioSessionGuid">Audio Session GUID (can be null)</param>
public void Initialize(AudioClientShareMode shareMode,
AudioClientStreamFlags streamFlags,
long bufferDuration,
long periodicity,
WaveFormat waveFormat,
Guid audioSessionGuid)
{
audioClientInterface.Initialize(shareMode, streamFlags, bufferDuration, periodicity, waveFormat, ref audioSessionGuid);
// may have changed the mix format so reset it
mixFormat = null;
}
示例8: Initialize
/// <summary>
/// Initializes the Audio Client
/// </summary>
/// <param name="shareMode">Share Mode</param>
/// <param name="streamFlags">Stream Flags</param>
/// <param name="bufferDuration">Buffer Duration</param>
/// <param name="periodicity">Periodicity</param>
/// <param name="waveFormat">Wave Format</param>
/// <param name="audioSessionGuid">Audio Session GUID (can be null)</param>
public void Initialize(AudioClientShareMode shareMode,
AudioClientStreamFlags streamFlags,
long bufferDuration,
long periodicity,
WaveFormat waveFormat,
Guid audioSessionGuid)
{
this.shareMode = shareMode;
int hresult = audioClientInterface.Initialize(shareMode, streamFlags, bufferDuration, periodicity, waveFormat, ref audioSessionGuid);
Marshal.ThrowExceptionForHR(hresult);
// may have changed the mix format so reset it
mixFormat = null;
}
示例9: WasapiOut
/// <summary>
/// Creates a new WASAPI Output
/// </summary>
/// <param name="device">Device to use</param>
/// <param name="shareMode"></param>
/// <param name="useEventSync">true if sync is done with event. false use sleep.</param>
/// <param name="latency"></param>
public WasapiOut(MMDevice device, AudioClientShareMode shareMode, bool useEventSync, int latency, AudioPCMConfig pcm)
{
this.audioClient = device.AudioClient;
this.shareMode = shareMode;
this.isUsingEventSync = useEventSync;
this.latencyMilliseconds = latency;
this.pcm = pcm;
this.outputFormat = new NAudio.Wave.WaveFormatExtensible(pcm.SampleRate, pcm.BitsPerSample, pcm.ChannelCount);
NAudio.Wave.WaveFormatExtensible closestSampleRateFormat;
if (!audioClient.IsFormatSupported(shareMode, outputFormat, out closestSampleRateFormat))
throw new NotSupportedException("PCM format mismatch");
Init();
bufferFrameCount = audioClient.BufferSize;
readBuffers = new AudioBuffer[2];
readBuffers[0] = new AudioBuffer(pcm, bufferFrameCount);
readBuffers[1] = new AudioBuffer(pcm, bufferFrameCount);
//if (this.shareMode == AudioClientShareMode.Exclusive)
// this.latencyMilliseconds = (int)(this.audioClient.DefaultDevicePeriod / 10000);
}
示例10: InitializeClient
private AudioClient InitializeClient(AudioClientShareMode shareMode)
{
AudioClient audioClient = GetAudioClient();
WaveFormat waveFormat = audioClient.MixFormat;
long refTimesPerSecond = 10000000;
audioClient.Initialize(shareMode,
AudioClientStreamFlags.None,
refTimesPerSecond,
0,
waveFormat,
Guid.Empty);
return audioClient;
}
示例11: IsFormatSupported
public bool IsFormatSupported(AudioClientShareMode shareMode, WAVEFORMATEXTENSIBLE format, ref WAVEFORMATEXTENSIBLE closestMatch)
{
int hr = _RealClient.IsFormatSupported(shareMode, format, out closestMatch);
bool ret = false;
if (hr == 0) ret = true;
else if (hr == 1) ret = false;
else Marshal.ThrowExceptionForHR(hr);
return ret;
}
示例12: WasapiCapture
/// <summary>
/// Initializes a new instance of the <see cref="WasapiCapture"/> class.
/// </summary>
/// <param name="eventSync">True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.</param>
/// <param name="shareMode">Specifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.</param>
/// <param name="latency">Latency of the capture specified in milliseconds.</param>
/// <param name="captureThreadPriority">ThreadPriority of the capturethread which runs in background and provides the audiocapture itself.</param>
/// <param name="defaultFormat">The default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.</param>
/// <param name="synchronizationContext">The <see cref="SynchronizationContext"/> to use to fire events on.</param>
/// <exception cref="PlatformNotSupportedException">The current platform does not support Wasapi. For more details see: <see cref="IsSupportedOnCurrentPlatform"/>.</exception>
/// <exception cref="ArgumentException">The <paramref name="eventSync"/> parameter is set to true while the <paramref name="shareMode"/> is set to <see cref="AudioClientShareMode.Exclusive"/>.</exception>
public WasapiCapture(bool eventSync, AudioClientShareMode shareMode, int latency, WaveFormat defaultFormat,
ThreadPriority captureThreadPriority, SynchronizationContext synchronizationContext)
{
if (!IsSupportedOnCurrentPlatform)
throw new PlatformNotSupportedException("Wasapi is only supported on Windows Vista and above.");
if (eventSync && shareMode == AudioClientShareMode.Exclusive)
throw new ArgumentException("Don't use eventSync in combination with exclusive mode.");
_eventSync = eventSync;
_shareMode = shareMode;
_waveFormat = defaultFormat;
_latency = latency;
_captureThreadPriority = captureThreadPriority;
_synchronizationContext = synchronizationContext;
_recordingState = RecordingState.Stopped;
}
示例13: IsFormatSupported
/// <summary>
/// Checks whether the audio endpoint device supports a particular stream format.
/// </summary>
public bool IsFormatSupported(AudioClientShareMode shareMode, WaveFormat waveFormat, out WaveFormatExtensible closestMatch)
{
int result = IsFormatSupportedNative(shareMode, waveFormat, out closestMatch);
switch (result)
{
case 0x0:
return true;
case 0x1:
case unchecked((int)0x88890008):
return false;
default:
CoreAudioAPIException.Try(result, c, "IsFormatSupported");
return false;
}
}
示例14: Initialize
public void Initialize(
AudioClientShareMode shareMode,
AudioClientStreamFlags streamFlags,
long bufferDuration, long periodicity,
WAVEFORMATEXTENSIBLE format, Guid audioSessionGuid)
{
int hr = _RealClient.Initialize(shareMode, streamFlags, bufferDuration, periodicity, format, ref audioSessionGuid);
Marshal.ThrowExceptionForHR(hr);
if ((streamFlags & AudioClientStreamFlags.EventCallback) != 0)
{
_audioSampleReady = new AutoResetEvent(false);
IntPtr eventHandle = CreateEventEx(IntPtr.Zero, "audioSampleReady", CreateEventFlags.None, AccessRight.Synchronize | AccessRight.EventModifyState);
_audioSampleReady.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(eventHandle, true);
hr = _RealClient.SetEventHandle(eventHandle);
Marshal.ThrowExceptionForHR(hr);
_audioSampleReadyRegistered = ThreadPool.RegisterWaitForSingleObject(
_audioSampleReady, new WaitOrTimerCallback(sampleReady), null, -1, false);
}
_isInitialized = true;
}
示例15: WasapiOut
/// <summary>
/// Initializes an new instance of <see cref="WasapiOut" /> class.
/// EventSyncContext = SynchronizationContext.Current.
/// PlaybackThreadPriority = AboveNormal.
/// </summary>
/// <param name="eventSync">True, to use eventsynchronization instead of a simple loop and sleep behavior.</param>
/// <param name="shareMode">
/// Specifies how to open the audio device. Note that if exclusive mode is used, only one single
/// playback for the specified device is possible at once.
/// </param>
/// <param name="latency">Latency of the playback specified in milliseconds.</param>
public WasapiOut(bool eventSync, AudioClientShareMode shareMode, int latency)
: this(eventSync, shareMode, latency, ThreadPriority.AboveNormal)
{
}