<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Capturing and streaming sound by using DirectSound with C#</title>
	<atom:link href="http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/</link>
	<description>Take care of the sense, and the sounds will take care of themselves.</description>
	<lastBuildDate>Sun, 14 Mar 2010 16:12:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ahmed</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3630</link>
		<dc:creator>Ahmed</dc:creator>
		<pubDate>Sat, 27 Feb 2010 21:46:03 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3630</guid>
		<description>what header files do i need?
can anyone please upload the codes?</description>
		<content:encoded><![CDATA[<p>what header files do i need?<br />
can anyone please upload the codes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dipak</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3613</link>
		<dc:creator>Dipak</dc:creator>
		<pubDate>Sat, 13 Feb 2010 12:04:11 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3613</guid>
		<description>Can we create a software to play fm without using any extra hardware other than computer&#039;s default hardware?

Is there any way?

Please reply.

Thank you.</description>
		<content:encoded><![CDATA[<p>Can we create a software to play fm without using any extra hardware other than computer&#8217;s default hardware?</p>
<p>Is there any way?</p>
<p>Please reply.</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Viktor</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3595</link>
		<dc:creator>Viktor</dc:creator>
		<pubDate>Thu, 04 Feb 2010 22:57:40 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3595</guid>
		<description>Hello!

The code works for me! Thx! (windows 7 x64)
But i have a problem:
I&#039;m capturing a webcam at the same time and the sound is laging about 0.4-0.7 seconds.
Can anyone help to &quot;make the sound faster&quot;?
Any solutions?

Thx</description>
		<content:encoded><![CDATA[<p>Hello!</p>
<p>The code works for me! Thx! (windows 7 x64)<br />
But i have a problem:<br />
I&#8217;m capturing a webcam at the same time and the sound is laging about 0.4-0.7 seconds.<br />
Can anyone help to &#8220;make the sound faster&#8221;?<br />
Any solutions?</p>
<p>Thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3558</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Thu, 14 Jan 2010 06:52:33 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3558</guid>
		<description>(Shame about all the formatting...!)

I&#039;ve just tested it again after some sleep and it&#039;s still glitching - can anyone suggest why?  Maybe I&#039;ll try writing code from scratch and see if that helps...</description>
		<content:encoded><![CDATA[<p>(Shame about all the formatting&#8230;!)</p>
<p>I&#8217;ve just tested it again after some sleep and it&#8217;s still glitching &#8211; can anyone suggest why?  Maybe I&#8217;ll try writing code from scratch and see if that helps&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3557</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Thu, 14 Jan 2010 06:33:29 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3557</guid>
		<description>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.DirectX.DirectSound;

using System.Threading;

namespace Echo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void StartButton_Click(object sender, EventArgs e)
        {
            if (!StartEcho(&quot;Input&quot;, this))          // change &quot;Input&quot; to something suitable
                MessageBox.Show(&quot;No matching Sound Card was found&quot;);
            // These parameters are guessed at - owner WAS Native.GetDesktopWindow()
        }

        private void StopButton_Click(object sender, EventArgs e)
        {
            IsReady = false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            IsReady = false;        // ensures the playback thread shuts down
        }




        // botch - not sure if these and IsReady are thread safe for multiple threads
        public int _dwCaptureBufferSize, _dwOutputBufferSize, _dwNotifySize;
        public CaptureBuffer _dwCapBuffer;
        public SecondaryBuffer[] _dwDevBuffers;
        public Thread _dwCaptureThread;

        public bool IsReady = false;
        // IsReady should be true while you wish to capture and then output the sound.

        private bool StartEcho(string captureDescriptor, Control owner)
        {
            // string captureDescriptor - string for eg &quot;Mic&quot;, &quot;Input&quot;
            // Control owner - maybe Window or Form would do for this - was Native.GetDesktopWindow()
            //                 if windowless application use desktop window as message broker
            // Returns true for setup done and thread started, false for problem


            // Choose a Wave format, calculating BlockAlign and AverageBytesPerSecond

            var format = new WaveFormat
            {
                SamplesPerSecond = 96000,
                BitsPerSample = 16,
                Channels = 2,
                FormatTag = WaveFormatTag.Pcm
            };

            // Both of these are calculate for All channels
            // BlockAlign = BytesPerSampleAllChannels, AverageBytesPerSecond = BytesPerSecondAllChannels 
            format.BlockAlign = (short)(format.Channels * (format.BitsPerSample / 8));
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;


            // Set the size of input and output buffers

            // Multiplier of both delay and minimum buffer size in units of 1/16th secs,
            int NUM_BUFFERS = 8;

            // Sets _dwNotifySize to enough bytes for 1/16th of a second, all channels
            // Note that this was 1/8th (ie line ended &#039;/ 8);&#039;), and output buffer size = capture size/2
            // But this was changed to allow output buffer size to be a multiple of BlockAlign
            _dwNotifySize = Math.Max(4096, format.AverageBytesPerSecond / (8*2));
            // rounds _dwNotifySize to a multiple of BlockAlign (BytesPerSampleAllChannel)
            _dwNotifySize -= _dwNotifySize % format.BlockAlign;

            // Capture buffer is looped - when the end is reached, it starts from the beginning again.
            // Capturing one should be twice as large as output - so that when completed capture
            // is being read to output buffer there is still room to for the buffer to keep filling
            // without overwriting the output. I think.
            _dwCaptureBufferSize = NUM_BUFFERS * _dwNotifySize * 2;
            _dwOutputBufferSize = NUM_BUFFERS * _dwNotifySize;

            // Create CaptureBufferDescriptor and actual capturing buffer
            // Enumerate all devices, choosing one containing the given string (captureDescriptor)
            var cap = default(Capture);
            var cdc = new CaptureDevicesCollection();
            for (int i = 0; i &lt; cdc.Count; i++)
            {
                if (cdc[i].Description.ToLower().Contains(captureDescriptor.ToLower()))
                {
                    cap = new Capture(cdc[i].DriverGuid);
                    break;
                }
            }

            // Check a matching capture device was found
            if (cap == null)
                return false;       // no matching sound card/capture device
            {

                // Make the description and create a CaptureBuffer accordingly
                var capDesc = new CaptureBufferDescription
                {
                    Format = format,
                    BufferBytes = _dwCaptureBufferSize
                };

                _dwCapBuffer = new CaptureBuffer(capDesc, cap);


                // Create output device and buffers

                // Uses default speakers to output - choose output device in same way as for capturing.
                var dev = new Device();
                // As DirectSound uses any window for a message pump we have to SetCooperativeLevel()
                dev.SetCooperativeLevel(owner, CooperativeLevel.Priority);

                // Set GlobalFocus=True if you want echo even if desktop window is not focused.
                var devDesc = new BufferDescription
                {
                    BufferBytes = _dwOutputBufferSize,
                    Format = format,
                    DeferLocation = true,
                    GlobalFocus = true
                };
                // Create two output buffers - this seems to avoid the buffer being locked and written
                // to while it&#039;s still playing, helping to avoid a sound glitch on my machine.
                _dwDevBuffers = new SecondaryBuffer[2];
                _dwDevBuffers[0] = new SecondaryBuffer(devDesc, dev);
                _dwDevBuffers[1] = new SecondaryBuffer(devDesc, dev);


                // Set autoResetEvent to be fired when it&#039;s filled and subscribe to buffer notifications

                var _resetEvent = new AutoResetEvent(false);
                var _notify = new Notify(_dwCapBuffer);
                // Half&amp;half - one notification halfway through the output buffer, one at the end
                var bpn1 = new BufferPositionNotify();
                bpn1.Offset = _dwCapBuffer.Caps.BufferBytes / 2 - 1;
                bpn1.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();
                var bpn2 = new BufferPositionNotify();
                bpn2.Offset = _dwCapBuffer.Caps.BufferBytes - 1;
                bpn2.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();

                _notify.SetNotificationPositions(new BufferPositionNotify[] { bpn1, bpn2 });


                IsReady = true;         // ready to capture sound

                // Fire worker thread to take care of messages
                // Note that on a uniprocessor, the new thread may not get any processor time 
                // until the main thread is preempted or yields, eg by ending button click event or
                // calling Thread.Sleep(0)

                // botch - not sure if these are thread safe for multiple threads
                int offset = 0;
                int devbuffer = 0;

                // Make a new thread - as countained in the { }
                _dwCaptureThread = new Thread((ThreadStart)delegate
                // *********************************************************************
                {
                    _dwCapBuffer.Start(true);   // start capture

                    // IsReady - This should be true while you wish to capture and then output the sound.
                    while (IsReady)
                    {
                        _resetEvent.WaitOne(); // blocks thread until _dwCapBuffer is half/totally full
                        // Read the capture buffer into an array, and output it to the next DevBuffer
                        var read = _dwCapBuffer.Read(offset, typeof(byte), LockFlag.None, _dwOutputBufferSize);
                        _dwDevBuffers[devbuffer].Write(0, read, LockFlag.EntireBuffer);

                        // Update offset
                        offset = (offset + _dwOutputBufferSize) % _dwCaptureBufferSize;

                        // Play the sound
                        _dwDevBuffers[devbuffer].SetCurrentPosition(0);
                        _dwDevBuffers[devbuffer].Play(0, BufferPlayFlags.Default);
                        devbuffer = 1 - devbuffer;  // toggle between 0 and 1
                    }
                    _dwCapBuffer.Stop();        // stop capture
                    // *********************************************************************
                });


                _dwCaptureThread.Start();           // start the new Thread

                return true;
            }
        }



    }
}</description>
		<content:encoded><![CDATA[<p>using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;</p>
<p>using Microsoft.DirectX.DirectSound;</p>
<p>using System.Threading;</p>
<p>namespace Echo<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }</p>
<p>        private void StartButton_Click(object sender, EventArgs e)<br />
        {<br />
            if (!StartEcho(&#8220;Input&#8221;, this))          // change &#8220;Input&#8221; to something suitable<br />
                MessageBox.Show(&#8220;No matching Sound Card was found&#8221;);<br />
            // These parameters are guessed at &#8211; owner WAS Native.GetDesktopWindow()<br />
        }</p>
<p>        private void StopButton_Click(object sender, EventArgs e)<br />
        {<br />
            IsReady = false;<br />
        }</p>
<p>        private void Form1_FormClosing(object sender, FormClosingEventArgs e)<br />
        {<br />
            IsReady = false;        // ensures the playback thread shuts down<br />
        }</p>
<p>        // botch &#8211; not sure if these and IsReady are thread safe for multiple threads<br />
        public int _dwCaptureBufferSize, _dwOutputBufferSize, _dwNotifySize;<br />
        public CaptureBuffer _dwCapBuffer;<br />
        public SecondaryBuffer[] _dwDevBuffers;<br />
        public Thread _dwCaptureThread;</p>
<p>        public bool IsReady = false;<br />
        // IsReady should be true while you wish to capture and then output the sound.</p>
<p>        private bool StartEcho(string captureDescriptor, Control owner)<br />
        {<br />
            // string captureDescriptor &#8211; string for eg &#8220;Mic&#8221;, &#8220;Input&#8221;<br />
            // Control owner &#8211; maybe Window or Form would do for this &#8211; was Native.GetDesktopWindow()<br />
            //                 if windowless application use desktop window as message broker<br />
            // Returns true for setup done and thread started, false for problem</p>
<p>            // Choose a Wave format, calculating BlockAlign and AverageBytesPerSecond</p>
<p>            var format = new WaveFormat<br />
            {<br />
                SamplesPerSecond = 96000,<br />
                BitsPerSample = 16,<br />
                Channels = 2,<br />
                FormatTag = WaveFormatTag.Pcm<br />
            };</p>
<p>            // Both of these are calculate for All channels<br />
            // BlockAlign = BytesPerSampleAllChannels, AverageBytesPerSecond = BytesPerSecondAllChannels<br />
            format.BlockAlign = (short)(format.Channels * (format.BitsPerSample / 8));<br />
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;</p>
<p>            // Set the size of input and output buffers</p>
<p>            // Multiplier of both delay and minimum buffer size in units of 1/16th secs,<br />
            int NUM_BUFFERS = 8;</p>
<p>            // Sets _dwNotifySize to enough bytes for 1/16th of a second, all channels<br />
            // Note that this was 1/8th (ie line ended &#8216;/ 8);&#8217;), and output buffer size = capture size/2<br />
            // But this was changed to allow output buffer size to be a multiple of BlockAlign<br />
            _dwNotifySize = Math.Max(4096, format.AverageBytesPerSecond / (8*2));<br />
            // rounds _dwNotifySize to a multiple of BlockAlign (BytesPerSampleAllChannel)<br />
            _dwNotifySize -= _dwNotifySize % format.BlockAlign;</p>
<p>            // Capture buffer is looped &#8211; when the end is reached, it starts from the beginning again.<br />
            // Capturing one should be twice as large as output &#8211; so that when completed capture<br />
            // is being read to output buffer there is still room to for the buffer to keep filling<br />
            // without overwriting the output. I think.<br />
            _dwCaptureBufferSize = NUM_BUFFERS * _dwNotifySize * 2;<br />
            _dwOutputBufferSize = NUM_BUFFERS * _dwNotifySize;</p>
<p>            // Create CaptureBufferDescriptor and actual capturing buffer<br />
            // Enumerate all devices, choosing one containing the given string (captureDescriptor)<br />
            var cap = default(Capture);<br />
            var cdc = new CaptureDevicesCollection();<br />
            for (int i = 0; i &lt; cdc.Count; i++)<br />
            {<br />
                if (cdc[i].Description.ToLower().Contains(captureDescriptor.ToLower()))<br />
                {<br />
                    cap = new Capture(cdc[i].DriverGuid);<br />
                    break;<br />
                }<br />
            }</p>
<p>            // Check a matching capture device was found<br />
            if (cap == null)<br />
                return false;       // no matching sound card/capture device<br />
            {</p>
<p>                // Make the description and create a CaptureBuffer accordingly<br />
                var capDesc = new CaptureBufferDescription<br />
                {<br />
                    Format = format,<br />
                    BufferBytes = _dwCaptureBufferSize<br />
                };</p>
<p>                _dwCapBuffer = new CaptureBuffer(capDesc, cap);</p>
<p>                // Create output device and buffers</p>
<p>                // Uses default speakers to output &#8211; choose output device in same way as for capturing.<br />
                var dev = new Device();<br />
                // As DirectSound uses any window for a message pump we have to SetCooperativeLevel()<br />
                dev.SetCooperativeLevel(owner, CooperativeLevel.Priority);</p>
<p>                // Set GlobalFocus=True if you want echo even if desktop window is not focused.<br />
                var devDesc = new BufferDescription<br />
                {<br />
                    BufferBytes = _dwOutputBufferSize,<br />
                    Format = format,<br />
                    DeferLocation = true,<br />
                    GlobalFocus = true<br />
                };<br />
                // Create two output buffers &#8211; this seems to avoid the buffer being locked and written<br />
                // to while it&#039;s still playing, helping to avoid a sound glitch on my machine.<br />
                _dwDevBuffers = new SecondaryBuffer[2];<br />
                _dwDevBuffers[0] = new SecondaryBuffer(devDesc, dev);<br />
                _dwDevBuffers[1] = new SecondaryBuffer(devDesc, dev);</p>
<p>                // Set autoResetEvent to be fired when it&#039;s filled and subscribe to buffer notifications</p>
<p>                var _resetEvent = new AutoResetEvent(false);<br />
                var _notify = new Notify(_dwCapBuffer);<br />
                // Half&amp;half &#8211; one notification halfway through the output buffer, one at the end<br />
                var bpn1 = new BufferPositionNotify();<br />
                bpn1.Offset = _dwCapBuffer.Caps.BufferBytes / 2 &#8211; 1;<br />
                bpn1.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();<br />
                var bpn2 = new BufferPositionNotify();<br />
                bpn2.Offset = _dwCapBuffer.Caps.BufferBytes &#8211; 1;<br />
                bpn2.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();</p>
<p>                _notify.SetNotificationPositions(new BufferPositionNotify[] { bpn1, bpn2 });</p>
<p>                IsReady = true;         // ready to capture sound</p>
<p>                // Fire worker thread to take care of messages<br />
                // Note that on a uniprocessor, the new thread may not get any processor time<br />
                // until the main thread is preempted or yields, eg by ending button click event or<br />
                // calling Thread.Sleep(0)</p>
<p>                // botch &#8211; not sure if these are thread safe for multiple threads<br />
                int offset = 0;<br />
                int devbuffer = 0;</p>
<p>                // Make a new thread &#8211; as countained in the { }<br />
                _dwCaptureThread = new Thread((ThreadStart)delegate<br />
                // *********************************************************************<br />
                {<br />
                    _dwCapBuffer.Start(true);   // start capture</p>
<p>                    // IsReady &#8211; This should be true while you wish to capture and then output the sound.<br />
                    while (IsReady)<br />
                    {<br />
                        _resetEvent.WaitOne(); // blocks thread until _dwCapBuffer is half/totally full<br />
                        // Read the capture buffer into an array, and output it to the next DevBuffer<br />
                        var read = _dwCapBuffer.Read(offset, typeof(byte), LockFlag.None, _dwOutputBufferSize);<br />
                        _dwDevBuffers[devbuffer].Write(0, read, LockFlag.EntireBuffer);</p>
<p>                        // Update offset<br />
                        offset = (offset + _dwOutputBufferSize) % _dwCaptureBufferSize;</p>
<p>                        // Play the sound<br />
                        _dwDevBuffers[devbuffer].SetCurrentPosition(0);<br />
                        _dwDevBuffers[devbuffer].Play(0, BufferPlayFlags.Default);<br />
                        devbuffer = 1 &#8211; devbuffer;  // toggle between 0 and 1<br />
                    }<br />
                    _dwCapBuffer.Stop();        // stop capture<br />
                    // *********************************************************************<br />
                });</p>
<p>                _dwCaptureThread.Start();           // start the new Thread</p>
<p>                return true;<br />
            }<br />
        }</p>
<p>    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3556</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Thu, 14 Jan 2010 06:31:37 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3556</guid>
		<description>Forgot to say that I also handled the Form&#039;s FormClosing event in Form1_FormClosing()</description>
		<content:encoded><![CDATA[<p>Forgot to say that I also handled the Form&#8217;s FormClosing event in Form1_FormClosing()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3555</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Thu, 14 Jan 2010 06:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3555</guid>
		<description>Apologies for the multiple posts - the web site said the posts had failed and gave an error.

The last post above is the final version of the three.

And now for the source code...</description>
		<content:encoded><![CDATA[<p>Apologies for the multiple posts &#8211; the web site said the posts had failed and gave an error.</p>
<p>The last post above is the final version of the three.</p>
<p>And now for the source code&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3554</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3554</guid>
		<description>Dear All,

Here is an annotated, working version of this code. It&#039;s the first time I&#039;ve done DirectSound, I don&#039;t understand it yet, and I&#039;m not finished tidying this up yet, but I wanted to quickly post it to help Vincent. Anyway, enough excuses!

I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events

private void StartButton_Click(object sender, EventArgs e)
private void StopButton_Click(object sender, EventArgs e)

You may need to change the string in StartEcho(&quot;Input&quot;, this) - look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.

I&#039;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled - ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) - please post with comments on this when you try it.

I&#039;m rusty on thread safe variables, and I&#039;ve not had time to do the research. As a result there are some variables that I&#039;m not sure if they are safe or not; I&#039;ve marked them. I think maybe they should be static volatile but it seems to work as is... If anyone can tell me what&#039;s right I&#039;d appreciate it.

If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same...

I hope this is helpful to someone, and I thank the original author, but suggest better, more complete and clearer code examples in the future.</description>
		<content:encoded><![CDATA[<p>Dear All,</p>
<p>Here is an annotated, working version of this code. It&#8217;s the first time I&#8217;ve done DirectSound, I don&#8217;t understand it yet, and I&#8217;m not finished tidying this up yet, but I wanted to quickly post it to help Vincent. Anyway, enough excuses!</p>
<p>I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events</p>
<p>private void StartButton_Click(object sender, EventArgs e)<br />
private void StopButton_Click(object sender, EventArgs e)</p>
<p>You may need to change the string in StartEcho(&#8220;Input&#8221;, this) &#8211; look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.</p>
<p>I&#8217;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled &#8211; ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) &#8211; please post with comments on this when you try it.</p>
<p>I&#8217;m rusty on thread safe variables, and I&#8217;ve not had time to do the research. As a result there are some variables that I&#8217;m not sure if they are safe or not; I&#8217;ve marked them. I think maybe they should be static volatile but it seems to work as is&#8230; If anyone can tell me what&#8217;s right I&#8217;d appreciate it.</p>
<p>If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same&#8230;</p>
<p>I hope this is helpful to someone, and I thank the original author, but suggest better, more complete and clearer code examples in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3553</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:43:55 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3553</guid>
		<description>Dear All,

Here is an annotated, working version of this code. I&#039;m not finished tidying this up yet but wanted to quickly post it to help Vincent.

I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events

private void StartButton_Click(object sender, EventArgs e)
private void StopButton_Click(object sender, EventArgs e)

You may need to change the string in StartEcho(&quot;Input&quot;, this) - look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.

I&#039;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled - ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) - please post with comments on this when you try it.

I&#039;m rusty on thread safe variables, and I&#039;ve not had time to do the research. As a result there are some variables that I&#039;m not sure if they are safe or not; I&#039;ve marked them. I think maybe they should be static volatile but it seems to work as is... If anyone can tell me what&#039;s right I&#039;d appreciate it.

If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same...

I hope this is helpful to someone, and I thank the original author, but suggest better, more complete and clearer code examples in the future.</description>
		<content:encoded><![CDATA[<p>Dear All,</p>
<p>Here is an annotated, working version of this code. I&#8217;m not finished tidying this up yet but wanted to quickly post it to help Vincent.</p>
<p>I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events</p>
<p>private void StartButton_Click(object sender, EventArgs e)<br />
private void StopButton_Click(object sender, EventArgs e)</p>
<p>You may need to change the string in StartEcho(&#8220;Input&#8221;, this) &#8211; look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.</p>
<p>I&#8217;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled &#8211; ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) &#8211; please post with comments on this when you try it.</p>
<p>I&#8217;m rusty on thread safe variables, and I&#8217;ve not had time to do the research. As a result there are some variables that I&#8217;m not sure if they are safe or not; I&#8217;ve marked them. I think maybe they should be static volatile but it seems to work as is&#8230; If anyone can tell me what&#8217;s right I&#8217;d appreciate it.</p>
<p>If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same&#8230;</p>
<p>I hope this is helpful to someone, and I thank the original author, but suggest better, more complete and clearer code examples in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Carlyle-Clarke</title>
		<link>http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/comment-page-1/#comment-3552</link>
		<dc:creator>James Carlyle-Clarke</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:42:27 +0000</pubDate>
		<guid isPermaLink="false">http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/#comment-3552</guid>
		<description>Dear All,

Here is an annotated, working version of this code. I&#039;m not finished tidying this up yet but wanted to quickly post it to help Vincent.

I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events

private void StartButton_Click(object sender, EventArgs e)
private void StopButton_Click(object sender, EventArgs e)

You may need to change the string in StartEcho(&quot;Input&quot;, this) - look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.

I&#039;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled - ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) - please post with comments on this when you try it.

I&#039;m rusty on thread safe variables, and I&#039;ve not had time to do the research. As a result there are some variables that I&#039;m not sure if they are safe or not; I&#039;ve marked them. I think maybe they should be static volatile but it seems to work as is... If anyone can tell me what&#039;s right I&#039;d appreciate it.

If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same...

I hope this is helpful to someone, and I thank the original poster, but suggest better, more complete and clearer code examples in the future.</description>
		<content:encoded><![CDATA[<p>Dear All,</p>
<p>Here is an annotated, working version of this code. I&#8217;m not finished tidying this up yet but wanted to quickly post it to help Vincent.</p>
<p>I created a C# Windows Forms project in Visual C# 2008. I added references to Microsoft.DirectX and Microsoft.DirectX.DirectSound. I added start and stop buttons called StartButton and StopButton with click events</p>
<p>private void StartButton_Click(object sender, EventArgs e)<br />
private void StopButton_Click(object sender, EventArgs e)</p>
<p>You may need to change the string in StartEcho(&#8220;Input&#8221;, this) &#8211; look in your Control Panel&gt;Sounds and Audio Devices, under Audio&gt;Sound recording&gt;Default device and choose part or all of that name.</p>
<p>I&#8217;ve made some changes to the code either for comprehension or to get it to work. With the updated code I _was_ getting a sound glitch about twice every time the output buffer filled &#8211; ie often. I think the buffer was being overwritten or locked while it was still playing, so I created two output buffers and it seems to work OK now, still the very occasional glitch but it might be my computer (no sound card!) &#8211; please post with comments on this when you try it.</p>
<p>I&#8217;m rusty on thread safe variables, and I&#8217;ve not had time to do the research. As a result there are some variables that I&#8217;m not sure if they are safe or not; I&#8217;ve marked them. I think maybe they should be static volatile but it seems to work as is&#8230; If anyone can tell me what&#8217;s right I&#8217;d appreciate it.</p>
<p>If I continue to improve it (rather than getting on with writing my own code) then I may post back, and I hope others will do the same&#8230;</p>
<p>I hope this is helpful to someone, and I thank the original poster, but suggest better, more complete and clearer code examples in the future.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
