<?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; capture</title>
	<atom:link href="http://www.jmsoftware.co.uk/blog/tag/capture/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>
	</channel>
</rss>

