本文整理汇总了C#中SharpDX.XAudio2.XAudio2.GetDeviceDetails方法的典型用法代码示例。如果您正苦于以下问题:C# XAudio2.GetDeviceDetails方法的具体用法?C# XAudio2.GetDeviceDetails怎么用?C# XAudio2.GetDeviceDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.XAudio2.XAudio2
的用法示例。
在下文中一共展示了XAudio2.GetDeviceDetails方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: X3DAudioEngine
public X3DAudioEngine()
{
_xaudio2 = new XAudio2();
_masteringVoice = new MasteringVoice(_xaudio2);
_deviceFormat = _xaudio2.GetDeviceDetails(0).OutputFormat;
_x3dAudio = new X3DAudio(_deviceFormat.ChannelMask);
Position = new Vector3D(0, 0, 0);
Rotation = System.Windows.Media.Media3D.Quaternion.Identity;
}
示例2: Main
static void Main(string[] args)
{
XAudio2 audioDevice = new XAudio2();
Console.WriteLine("Device count: " + audioDevice.DeviceCount);
for (int indexOfDevice = 0; indexOfDevice < audioDevice.DeviceCount; indexOfDevice++)
{
DeviceDetails deviceDetails = audioDevice.GetDeviceDetails(indexOfDevice);
Console.WriteLine("DeviceID: " + deviceDetails.DeviceID);
Console.WriteLine("Device Name: " + deviceDetails.DisplayName);
Console.WriteLine("Output format:" + deviceDetails.OutputFormat);
Console.WriteLine("Role: " + deviceDetails.Role);
Console.WriteLine();
}
MasteringVoice masteringVoice = new MasteringVoice(audioDevice);
Console.WriteLine("Volume: " + masteringVoice.Volume);
Console.ReadKey();
}
示例3: StartEngine
private void StartEngine()
{
if (m_audioEngine != null)
{
DisposeVoices();
m_audioEngine.CriticalError -= m_audioEngine_CriticalError;
m_audioEngine.Dispose();
}
// Init/reinit engine
m_audioEngine = new XAudio2(XAudio2Version.Version27);
// A way to disable SharpDX callbacks
//var meth = m_audioEngine.GetType().GetMethod("UnregisterForCallbacks_", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
//var callbacks = m_audioEngine.GetType().GetField("engineShadowPtr", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
//meth.Invoke((object)m_audioEngine, new object[] { callbacks.GetValue(m_audioEngine) });
m_audioEngine.CriticalError += m_audioEngine_CriticalError;
m_lastDeviceCount = m_audioEngine.DeviceCount;
m_deviceNumber = 0;
while (true) //find first non com device
{
try
{
m_deviceDetails = m_audioEngine.GetDeviceDetails(m_deviceNumber);
if (m_deviceDetails.Role == DeviceRole.DefaultCommunicationsDevice)
{
m_deviceNumber++;
if (m_deviceNumber == m_audioEngine.DeviceCount)
{
m_deviceNumber--;
break;
}
}
else
break;
}
catch(Exception e)
{
MyLog.Default.WriteLine(string.Format("Failed to get device details.\n\tdevice no.: {0}\n\tdevice count: {1}",m_deviceNumber, m_audioEngine.DeviceCount),LoggingOptions.AUDIO);
MyLog.Default.WriteLine(e.ToString());
m_deviceNumber = 0;
m_deviceDetails = m_audioEngine.GetDeviceDetails(m_deviceNumber);
break;
}
}
m_masterVoice = new MasteringVoice(m_audioEngine, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, m_deviceNumber);
if (m_useVolumeLimiter)
{
var limiter = new SharpDX.XAPO.Fx.MasteringLimiter(m_audioEngine);
var param = limiter.Parameter;
param.Loudness = 0;
limiter.Parameter = param;
//TODO: this throws exception in 3.0.1 version
var effectDescriptor = new EffectDescriptor(limiter);
m_masterVoice.SetEffectChain(effectDescriptor);
m_soundLimiterReady = true;
m_masterVoice.DisableEffect(0);
//m_masterVoice.EnableEffect(0);
//limiter.Dispose();
}
m_calculateFlags = CalculateFlags.Matrix | CalculateFlags.Doppler;
if ((m_deviceDetails.OutputFormat.ChannelMask & Speakers.LowFrequency) != 0)
{
m_calculateFlags |= CalculateFlags.RedirectToLfe;
}
var masterDetails = m_masterVoice.VoiceDetails;
m_gameAudioVoice = new SubmixVoice(m_audioEngine, masterDetails.InputChannelCount, masterDetails.InputSampleRate);
m_musicAudioVoice = new SubmixVoice(m_audioEngine, masterDetails.InputChannelCount, masterDetails.InputSampleRate);
m_hudAudioVoice = new SubmixVoice(m_audioEngine, masterDetails.InputChannelCount, masterDetails.InputSampleRate);
m_gameAudioVoiceDesc = new VoiceSendDescriptor[] { new VoiceSendDescriptor(m_gameAudioVoice) };
m_musicAudioVoiceDesc = new VoiceSendDescriptor[] { new VoiceSendDescriptor(m_musicAudioVoice) };
m_hudAudioVoiceDesc = new VoiceSendDescriptor[] { new VoiceSendDescriptor(m_hudAudioVoice) };
if (m_mute)
{ // keep sounds muted
m_gameAudioVoice.SetVolume(0);
m_musicAudioVoice.SetVolume(0);
}
m_reverb = new Reverb(m_audioEngine);
m_gameAudioVoice.SetEffectChain(new EffectDescriptor(m_reverb, masterDetails.InputChannelCount));
m_gameAudioVoice.DisableEffect(0);
}
示例4: SoundEffect
static SoundEffect()
{
var flags = XAudio2Flags.None;
#if !WINRT && DEBUG
flags |= XAudio2Flags.DebugEngine;
#endif
try
{
// This cannot fail.
Device = new XAudio2(flags, ProcessorSpecifier.DefaultProcessor);
Device.StartEngine();
// Just use the default device.
#if WINRT
string deviceId = null;
#else
const int deviceId = 0;
#endif
// Let windows autodetect number of channels and sample rate.
MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceId);
MasterVoice.SetVolume(_masterVolume, 0);
// The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
#if WINRT
Speakers = (Speakers)MasterVoice.ChannelMask;
#else
var deviceDetails = Device.GetDeviceDetails(deviceId);
Speakers = deviceDetails.OutputFormat.ChannelMask;
#endif
}
catch
{
// Release the device and null it as
// we have no audio support.
if (Device != null)
{
Device.Dispose();
Device = null;
}
MasterVoice = null;
}
}
示例5: Main
/// <summary>
/// SharpDX X3DAudio sample. Plays a generated sound rotating around the listener.
/// </summary>
static void Main(string[] args)
{
var xaudio2 = new XAudio2();
using (var masteringVoice = new MasteringVoice(xaudio2))
{
// Instantiate X3DAudio
var deviceFormat = xaudio2.GetDeviceDetails(0).OutputFormat;
var x3dAudio = new X3DAudio(deviceFormat.ChannelMask);
var emitter = new Emitter
{
ChannelCount = 1,
CurveDistanceScaler = float.MinValue,
OrientFront = new Vector3(0, 0, 1),
OrientTop = new Vector3(0, 1, 0),
Position = new Vector3(0, 0, 0),
Velocity = new Vector3(0, 0, 0)
};
var listener = new Listener
{
OrientFront = new Vector3(0, 0, 1),
OrientTop = new Vector3(0, 1, 0),
Position = new Vector3(0, 0, 0),
Velocity = new Vector3(0, 0, 0)
};
var waveFormat = new WaveFormat(44100, 32, 1);
var sourceVoice = new SourceVoice(xaudio2, waveFormat);
int bufferSize = waveFormat.ConvertLatencyToByteSize(60000);
var dataStream = new DataStream(bufferSize, true, true);
int numberOfSamples = bufferSize/waveFormat.BlockAlign;
for (int i = 0; i < numberOfSamples; i++)
{
float value = (float) (Math.Cos(2*Math.PI*220.0*i/waveFormat.SampleRate)*0.5);
dataStream.Write(value);
}
dataStream.Position = 0;
var audioBuffer = new AudioBuffer
{Stream = dataStream, Flags = BufferFlags.EndOfStream, AudioBytes = bufferSize};
//var reverb = new Reverb();
//var effectDescriptor = new EffectDescriptor(reverb);
//sourceVoice.SetEffectChain(effectDescriptor);
//sourceVoice.EnableEffect(0);
sourceVoice.SubmitSourceBuffer(audioBuffer, null);
sourceVoice.Start();
Console.WriteLine("Play a sound rotating around the listener");
for (int i = 0; i < 1200; i++)
{
// Rotates the emitter
var rotateEmitter = Matrix.RotationY(i/5.0f);
var newPosition = Vector3.Transform(new Vector3(0, 0, 1000), rotateEmitter);
var newPositionVector3 = new Vector3(newPosition.X, newPosition.Y, newPosition.Z);
emitter.Velocity = (newPositionVector3 - emitter.Position)/0.05f;
emitter.Position = newPositionVector3;
// Calculate X3DAudio settings
var dspSettings = x3dAudio.Calculate(listener, emitter, CalculateFlags.Matrix | CalculateFlags.Doppler , 1, deviceFormat.Channels);
// Modify XAudio2 source voice settings
sourceVoice.SetOutputMatrix(1, deviceFormat.Channels, dspSettings.MatrixCoefficients);
sourceVoice.SetFrequencyRatio(dspSettings.DopplerFactor);
// Wait for 50ms
Thread.Sleep(50);
}
}
}