<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>JMSoftware &#187; DirectSound</title>
	<atom:link href="http://www.jmsoftware.co.uk/blog/category/programming/directsound/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jmsoftware.co.uk</link>
	<description>Software Development</description>
	<lastBuildDate>Mon, 26 Sep 2011 13:38:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>The DirectSound Capture Buffer</title>
		<link>http://www.jmsoftware.co.uk/blog/the-directsound-capture-buffer</link>
		<comments>http://www.jmsoftware.co.uk/blog/the-directsound-capture-buffer#comments</comments>
		<pubDate>Fri, 09 Jan 2009 16:58:23 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[DirectSound]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[capturebuffer]]></category>
		<category><![CDATA[directx]]></category>
		<category><![CDATA[notify]]></category>

		<guid isPermaLink="false">http://www.jmsoftware.co.uk/?p=123</guid>
		<description><![CDATA[A CaptureBuffer is a buffer of a specified length that reads audio from a Capture object which represents the capture (or input) device, into a one-dimensional array of bytes with a specified WaveFormat. The capture buffer can be used in &#8230; <a href="http://www.jmsoftware.co.uk/blog/the-directsound-capture-buffer">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A <strong>CaptureBuffer</strong> is a buffer of a specified length that reads audio from a <strong>Capture</strong> object which represents the capture (or input) device, into a one-dimensional array of bytes with a specified <strong>WaveFormat</strong>.</p>
<p><span id="more-123"></span>The capture buffer can be used in two ways. As a <em>static buffer</em>, which stops when the buffer is full, or a <em>streaming buffer</em>, where once the buffer is full it returns to the start and begins overwriting the samples. You obviously need to read and do something with the data before this happens.</p>
<p>One method is to set up a <strong>Notify</strong> object, giving it an array of <strong>BufferPositionNotify</strong> objects. These contain the handle for an event, and the buffer offset at which to fire that event. This is usually an <strong>AutoResetEvent</strong>, monitored by a separate thread which then reads a section of the buffer, and processes that data. One problem is that they can be unreliable if another program is also using DirectSound notifications at the same time. You may start receiving those as well, or even have yours go missing.</p>
<p>The other option is to monitor it yourself, periodically checking the write position of the capture buffer through its <strong>GetCurrentPosition</strong> function. When you see that it has moved past a certain point (i.e. an offset position) you can then process that chunk of data as before.</p>
<p>To make a CaptureBuffer, first instantiate a new <strong>Capture</strong> object. Use no parameters or a <strong>Guid.Empty</strong> for the default device, or give it the Guid or an IntPtr to the device you want to use. The available devices can be discovered by creating a <strong>CaptureDevicesCollection</strong> object.</p>
<p>Then use this Capture object to a create a new <strong>CaptureBuffer</strong>, along with a WaveFormat, and the length of the buffer you want.</p>
<p>Reading the buffer is accomplished by simply calling the Read function with the start position, number of bytes to read, and a <strong>LockFlag</strong> to say if you want to prevent the data from being overwritten while you read it. Finally, cast the resultant <strong>Array</strong> to an array of bytes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jmsoftware.co.uk/blog/the-directsound-capture-buffer/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>An Explanation of Output Buffers in DirectSound</title>
		<link>http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound</link>
		<comments>http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound#comments</comments>
		<pubDate>Tue, 06 Jan 2009 02:07:57 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[DirectSound]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[directx]]></category>
		<category><![CDATA[primary]]></category>
		<category><![CDATA[secondary]]></category>

		<guid isPermaLink="false">http://www.jmsoftware.co.uk/?p=65</guid>
		<description><![CDATA[A DirectSound Buffer is a one-dimensional array of bytes which represent sound waves in a digital form. The data is laid out in a specified Microsoft.DirectX.DirectSound.WaveFormat which specifies the format type, number of channels, number of samples per second and &#8230; <a href="http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A DirectSound Buffer is a one-dimensional array of bytes which represent sound waves in a digital form. The data is laid out in a specified <em>Microsoft.DirectX.DirectSound.WaveFormat</em> which specifies the format type, number of channels, number of samples per second and so on.<sup><a href="http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound#footnote_0_65" id="identifier_0_65" class="footnote-link footnote-identifier-link" title="Only data which matches that format can be loaded into the an output buffer. Sound data with different formats can be played at the same time by using separate secondary buffers for each.">1</a></sup></p>
<p>Each byte is a part of a <em>sample</em>, and a sample represents the average amplitude of the sound waves position at that point in time.<sup><a href="http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound#footnote_1_65" id="identifier_1_65" class="footnote-link footnote-identifier-link" title="Remember that sound is a waveform, and the buffer contains the actual wave data. Filling it with just one value will produce silence as the speaker cones will not move. To produce a tone programatically you need to fill the buffer with a waveform, such as a Sine Wave, a Square Wave, a Triangle Wave, or a Sawtooth Wave.">2</a></sup></p>
<p>There are two types of buffers used for output: Primary and Secondary. These both send data to an output device, represented by a <em>Microsoft.DirectX.DirectSound.Device</em> object.<br />
<span id="more-65"></span><br />
<hr />
<p><b>Primary Buffer</b></p>
<p>There is only one Primary Buffer for a device, and the data it contains is exactly what will come out of that device.</p>
<p>Accessing and changing the primary buffer is possible, but usually unnecessary. It&#8217;s better to let DirectX handle the mixing, or you will have to take responsibility for outputting the buffer in real-time. You also lose the ability to use secondary buffers, and it prevents other applications from using buffers.</p>
<p>To access the primary buffer, create a <em>Microsoft.DirectX.DirectSound.Buffer</em> object using a DirectSound Device with its cooperative level set to <em>CooperativeLevel.WritePrimary</em>.</p>
<hr />
<p><b>Secondary Buffer</b></p>
<p>The secondary buffer is a buffer of a specified size, and contains sound data ready to be output. An application can have as many secondary buffers as it wants, within memory limits.</p>
<p>When you call a buffer&#8217;s Play function the content is mixed into the primary buffer and output by DirectX.</p>
<p>If called with the <em>BufferPlayFlags.Looping</em> flag set, it will play the buffer from start to finish over and over again until stopped. By continually writing new data into the buffer just ahead of the current play position it is possible to output audio that would not have fitted into memory, or that did not even exist when you started the buffer. This is known as <em>streaming</em>.</p>
<p>You can either use a <em>Microsoft.DirectX.DirectSound.Buffer</em>, or a <em>Microsoft.DirectX.DirectSound.SecondaryBuffer</em> which inherits the previous and adds support for effects such as distortion, compression, reverb, and more.</p>
<hr />
<ol class="footnotes"><li id="footnote_0_65" class="footnote">Only data which matches that format can be loaded into the an output buffer. Sound data with different formats can be played at the same time by using separate secondary buffers for each.</li><li id="footnote_1_65" class="footnote">Remember that sound is a waveform, and the buffer contains the actual wave data. Filling it with just one value will produce silence as the speaker cones will not move. To produce a tone programatically you need to fill the buffer with a waveform, such as a Sine Wave, a Square Wave, a Triangle Wave, or a Sawtooth Wave.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.jmsoftware.co.uk/blog/an-explanation-of-output-buffers-in-directsound/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

