private void SubmitAudioBuffer() { var streamData = mAudioQueue.ReadAudio(); if (streamData == null) { return; } if (mStreamBuffer[mCurrentBuffer] == null || mStreamBuffer[mCurrentBuffer].Size != streamData.Length) { mStreamBuffer[mCurrentBuffer]?.Dispose(); mStreamBuffer[mCurrentBuffer] = new SharpDX.DataBuffer(streamData.Length); } mStreamBuffer[mCurrentBuffer].Set(0, streamData); var buffer = new SharpDX.XAudio2.AudioBuffer(mStreamBuffer[mCurrentBuffer]) { Flags = SharpDX.XAudio2.BufferFlags.None }; mSourceVoice.SubmitSourceBuffer(buffer, null); mCurrentBuffer = (mCurrentBuffer + 1) % mBufferCount; }
internal SoundEffect(SharpDX.XAudio2.XAudio2 device, SharpDX.Multimedia.SoundStream waveStream) { if (waveStream == null) throw new ArgumentNullException("waveStream"); this.audioBuffer = new SharpDX.XAudio2.AudioBuffer(); this.audioBuffer.Stream = waveStream; this.audioBuffer.AudioBytes = (int)waveStream.Length; this.sourceVoice = new SharpDX.XAudio2.SourceVoice(device, waveStream.Format); }
protected override void Dispose(bool disposing) { if (disposing) { if (this.sourceVoice != null) { this.sourceVoice.Dispose(); this.sourceVoice = null; } if (this.audioBuffer != null) { this.audioBuffer.Stream.Close(); this.audioBuffer = null; } } }
/// <summary> /// No documentation. /// </summary> /// <param name="bufferRef">No documentation.</param> /// <param name="decodedXMWAPacketInfo">No documentation.</param> /// <returns>No documentation.</returns> /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IXAudio2SourceVoice::SubmitSourceBuffer']/*"/> /// <unmanaged>HRESULT IXAudio2SourceVoice::SubmitSourceBuffer([In] const XAUDIO2_BUFFER* pBuffer,[In, Optional] const XAUDIO2_BUFFER_WMA* pBufferWMA)</unmanaged> public void SubmitSourceBuffer(SharpDX.XAudio2.AudioBuffer bufferRef, uint[] decodedXMWAPacketInfo) { unsafe { if (decodedXMWAPacketInfo != null) { fixed(void *pBuffer = decodedXMWAPacketInfo) { SharpDX.XAudio2.BufferWma bufferWmaRef; bufferWmaRef.PacketCount = decodedXMWAPacketInfo.Length; bufferWmaRef.DecodedPacketCumulativeBytesPointer = (IntPtr)pBuffer; SubmitSourceBuffer(bufferRef, new IntPtr(&bufferWmaRef)); } } else { SubmitSourceBuffer(bufferRef, IntPtr.Zero); } } }
public XA2Buffer() { _buffer = new SharpDX.XAudio2.AudioBuffer(); }