/// <summary> /// Creates the XAudio2. /// </summary> private void CreateXAudio2() { try { _xaudio2 = new XAudio2_8(XAudio2Processor.Xaudio2DefaultProcessor); } catch (Exception) { try { _xaudio2 = new XAudio2_7(false, XAudio2Processor.Xaudio2DefaultProcessor); } catch { } } }
internal StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, VoiceCallback voiceCallback, int bufferSize) : base(CreateSourceVoice(xaudio2, waveSource, voiceCallback), xaudio2.Version) { _voiceCallback = voiceCallback; _waveSource = waveSource; var maxBufferBytes = (int)waveSource.WaveFormat.MillisecondsToBytes(bufferSize); _buffer = new byte[maxBufferBytes]; for (int i = 0; i < _buffers.Length; i++) { var buffer = new XAudio2Buffer(maxBufferBytes); _buffers[i] = buffer; } InitializeForStreaming(); }
/// <summary> /// Initializes a new XAudio2SoundProvider class /// <param name="xaudio2">The XAudio2 Instance.</param> /// <param name="soundInitializer">The ISoundInitializer.</param> /// </summary> internal XAudio2SoundProvider(CSCore.XAudio2.XAudio2 xaudio2, ISoundInitializer soundInitializer) { SoundInitializer = soundInitializer; _xaudio2 = xaudio2; _xaudio2.CreateMasteringVoice(); }
public void Initialize() { _source = GlobalTestConfig.TestMp3(); _xaudio2 = CreateXAudio2(); }
/// <summary> /// Creates an instance of the <see cref="StreamingSourceVoice" /> class. /// </summary> /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class.</param> /// <param name="waveSource"><see cref="IWaveSource" /> which provides the audio data to stream.</param> /// <param name="bufferSize"> /// Buffersize of the internal used buffers in milliseconds. Values in the range from 70ms to /// 200ms are recommended. /// </param> /// <returns>Configured <see cref="StreamingSourceVoice" /> instance.</returns> public static StreamingSourceVoice Create(XAudio2 xaudio2, IWaveSource waveSource, int bufferSize = 100) { var voiceCallback = new VoiceCallback(); IntPtr ptr = xaudio2.CreateSourceVoicePtr(waveSource.WaveFormat, VoiceFlags.None, XAudio2.DefaultFrequencyRatio, voiceCallback, null, null); return new StreamingSourceVoice(ptr, voiceCallback, waveSource, bufferSize); }
/// <summary> /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class. /// </summary> /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param> /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param> /// <param name="bufferSize"> /// Buffersize of the internal buffers, in milliseconds. Values in the range from 70ms to /// 200ms are recommended. /// </param> public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, int bufferSize) : this(xaudio2, waveSource, new VoiceCallback(), bufferSize) { }
/// <summary> /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class with a default buffer size of 100ms. /// </summary> /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param> /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param> public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource) : this(xaudio2, waveSource, 100) { }
private static IntPtr CreateSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, VoiceCallback callback) { if (xaudio2 == null) throw new ArgumentNullException("xaudio2"); if (waveSource == null) throw new ArgumentNullException("waveSource"); return xaudio2.CreateSourceVoicePtr(waveSource.WaveFormat, VoiceFlags.None, XAudio2.DefaultFrequencyRatio, callback, null, null); }