<?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/"
	>

<channel>
	<title>Inchoate Thoughts &#187; Jacob</title>
	<atom:link href="http://inchoatethoughts.com/author/admin/feed" rel="self" type="application/rss+xml" />
	<link>http://inchoatethoughts.com</link>
	<description>Drums, Computers, and Disjointed Ramblings</description>
	<lastBuildDate>Tue, 05 Apr 2011 22:27:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WPFSVL and NAudio</title>
		<link>http://inchoatethoughts.com/wpfsvl-and-naudio</link>
		<comments>http://inchoatethoughts.com/wpfsvl-and-naudio#comments</comments>
		<pubDate>Mon, 04 Apr 2011 02:45:53 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[NAudio]]></category>
		<category><![CDATA[Spectrum Analyzer]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Visualizer]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=510</guid>
		<description><![CDATA[By popular demand, I&#8217;ve added an example of how to use the WPFSVL with NAudio as the sound engine powering it. I&#8217;m still plugging away at the &#8220;getting started&#8221; documentation for both BASS and NAudio, but if you get the latest source for WPFSVL, you&#8217;ll now have an example application to work from. The way [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_511" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/04/BassAndNAudio.png"><img class="size-medium wp-image-511" title="WPFSVL Now Has NAudio Examples" src="http://inchoatethoughts.com/wp-content/uploads/2011/04/BassAndNAudio-300x84.png" alt="WPFSVL Now Has NAudio Examples" width="300" height="84" /></a><p class="wp-caption-text">WPFSVL Now Has NAudio Examples</p></div>
<p>By popular demand, I&#8217;ve added an example of how to use the WPFSVL with <a href="http://naudio.codeplex.com/" target="_blank">NAudio</a> as the sound engine powering it. I&#8217;m still plugging away at the &#8220;getting started&#8221; documentation for both BASS and NAudio, but if you get the latest source for WPFSVL, you&#8217;ll now have an example application to work from. The way I do sample updates and stereo FFT updates is actually a bit different from anything included in the normal NAudio examples, so I encourage you NAudioers to check it out. The normal examples do FFT at every complete sampling. I have it set up to only do FFT on request from the spectrum analyzer, so my performance seems a bit snappier than other NAudio sample applications out there.</p>
<p>I haven&#8217;t had as much time to work out the kinks in the NAudio example, so let me know if you&#8217;re seeing anything odd. I know I&#8217;m still struggling with certain MP3 files returning strange level data on the waveform. Also, since NAudio is managed code, the performance isn&#8217;t quite as snappy as the BASS examples (but still quite decent).</p>
<p><a href="http://wpfsvl.codeplex.com/" target="_blank">Get the WPF Sound Visualization Library at CodePlex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/wpfsvl-and-naudio/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WPF Sound Visualization Library</title>
		<link>http://inchoatethoughts.com/wpf-sound-visualization-library</link>
		<comments>http://inchoatethoughts.com/wpf-sound-visualization-library#comments</comments>
		<pubDate>Fri, 25 Mar 2011 04:04:02 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Album Art]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[BASS]]></category>
		<category><![CDATA[BASS.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Spectrum Analyzer]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Visualizer]]></category>
		<category><![CDATA[Waveform]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=495</guid>
		<description><![CDATA[I&#8217;ve just launched my first CodePlex project, The WPF Sound Visualization Library. This thing is actually an extension of the Spectrum Analyzer control I made and part of a much larger secret project. Essentially, I&#8217;m taking all the WPF controls I&#8217;m creating in my other big project, dumping them out to their own project, slapping [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_496" class="wp-caption aligncenter" style="width: 188px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/ControlLibraryThemes.png"><img class="size-medium wp-image-496" title="WPF SVL supports themes/templating!" src="http://inchoatethoughts.com/wp-content/uploads/2011/03/ControlLibraryThemes-178x300.png" alt="WPF SVL supports themes/templating!" width="178" height="300" /></a><p class="wp-caption-text">WPF SVL supports themes/templating!</p></div>
<p>I&#8217;ve just launched my <a title="WPF Sound Visualization Library CodePlex Project" href="http://wpfsvl.codeplex.com/" target="_blank">first CodePlex project</a>, The WPF Sound Visualization Library. This thing is actually an extension of the <a title="A WPF Spectrum Analyzer for Audio Visualization " href="http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening" target="_blank">Spectrum Analyzer control</a> I made and part of a much larger secret project. Essentially, I&#8217;m taking all the WPF controls I&#8217;m creating in my other big project, dumping them out to their own project, slapping an MIT license on it, and releasing it to the public. They all have the common theme of being controls related to sound visualization/playback. Everything was designed so the look could be customized. I&#8217;m always looking for ways to improve their flexibility, so if you have ideas, let me know.</p>
<p>&nbsp;</p>
<p><strong>Stereo Waveform Timeline</strong></p>
<div id="attachment_497" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/Waveform.png"><img class="size-medium wp-image-497" title="Introducing The Waveform Timeline" src="http://inchoatethoughts.com/wp-content/uploads/2011/03/Waveform-300x43.png" alt="Introducing The Waveform Timeline" width="300" height="43" /></a><p class="wp-caption-text">Introducing The Waveform Timeline</p></div>
<p>First up is a Waveform. I&#8217;ve seen a few people struggling to create these on the BASS forums, so I hope this is useful to the community. Right now, it only has stereo support. I hope to support Mono, Quad, and 5.1 channel displays soon. Aside from displaying a Waveform, this thing has the ability to set track position and a repeat section in the audio stream it is rendering.</p>
<p>One of the challenges in displaying a Waveform in WPF is making sure that it doesn&#8217;t kill performance while not appearing blurry. I&#8217;ve taken advantage of BitmapCache and some special scaling code so that this is handled well. The Waveform Timeline is broken down into four template parts: the waveform canvas, the timeline canvas, the progress indicator canvas, and the repeat region overlay canvas.</p>
<p><strong>Spectrum Analyzer</strong></p>
<div id="attachment_498" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/SpecAn.png"><img class="size-medium wp-image-498" title="Our Old Friend - The Spectrum Analyzer" src="http://inchoatethoughts.com/wp-content/uploads/2011/03/SpecAn-300x185.png" alt="Our Old Friend - The Spectrum Analyzer" width="300" height="185" /></a><p class="wp-caption-text">Our Old Friend - The Spectrum Analyzer</p></div>
<p>Next is my old friend the Spectrum Analyzer. Nothing really new to report here. I have lots of detail on this in my previous blog posts. I should note, however, there are a few minor fixes and an added property or two since the last time I posted Spectrum Analyzer source code to this blog.</p>
<p><strong>Album Art Display</strong></p>
<div id="attachment_499" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/AlbumArt.png"><img class="size-medium wp-image-499" title="Album Art Display - For Those Who Bought Music Before iTunes" src="http://inchoatethoughts.com/wp-content/uploads/2011/03/AlbumArt-300x131.png" alt="Album Art Display - For Those Who Bought Music Before iTunes" width="300" height="131" /></a><p class="wp-caption-text">Album Art Display - For Those Who Bought Music Before iTunes</p></div>
<p>Finally, we have an album art display. Basically, it&#8217;ll take the album art image (presumably from MP3/AAC tags) and display it in a jewel case. I don&#8217;t know how much longer the kids will even remember jewel cases, but I still think they look cool in media applications. I&#8217;ve had the Album Art Display in a few of my example applications already, but I&#8217;ve refactored it a bit so it was a Control rather than a UserControl.</p>
<p><a title="WPF Sound Visualization Library" href="http://wpfsvl.codeplex.com/" target="_blank"><strong>Check Out The CodePlex Project!</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/wpf-sound-visualization-library/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A WPF Spectrum Analyzer for Audio Visualization (C#) &#8211; Part 2: The WPFening</title>
		<link>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening</link>
		<comments>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening#comments</comments>
		<pubDate>Sun, 20 Mar 2011 04:07:25 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[BASS]]></category>
		<category><![CDATA[BASS.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Spectrum Analyzer]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Visualizer]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=422</guid>
		<description><![CDATA[UPDATE:The WPF Spectrum Analyzer is now part of the WPF Sound Visualization Library. That is where you will find source code for the latest and most-stable versions of the Spectrum Analyzer. &#8212; A number of weeks ago, I shared with the world a WPF Spectrum Analyzer UserControl I had created. This post is an update [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong>The WPF Spectrum Analyzer is now part of the <a href="http://wpfsvl.codeplex.com/" target="_blank">WPF Sound Visualization Library</a>. That is where you will find source code for the latest and most-stable versions of the Spectrum Analyzer.</p>
<p>&#8212;</p>
<p><div id="attachment_483" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/SpectrumNormalSize.png"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/03/SpectrumNormalSize-300x216.png" alt="The Spectrum Analyzer Control" title="The Spectrum Analyzer Control" width="300" height="216" class="size-medium wp-image-483" /></a><p class="wp-caption-text">The Spectrum Analyzer Control</p></div><br />
A number of weeks ago, I shared with the world a <a href="http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization">WPF Spectrum Analyzer UserControl</a> I had created. This post is an update on that. Why is there an update? Well, I&#8217;ve made some pretty fundamental changes to the Spectrum Analyzer. Not changes that an end-user would necessarily notice at first glance, but they&#8217;re fundamental to the way the control performs. I was dissatisfied with the first iteration of the Spectrum Analyzer for two reasons:</p>
<ol>
<li>It didn&#8217;t support scaling.</li>
<li>It was a UserControl, which means that didn&#8217;t support custom templates/themes.</li>
</ol>
<p>These two inadequacies severely crippled much of what makes WPF so great.</p>
<p><strong>Supporting Scaling &#8211; Go Go Gadget Vectors!</strong></p>
<p>My first pass at the Spectrum Analyzer was based on a very bad assumption. I assumed, foolishly, that a classic pixel-based rendering loop where I manually controlled the buffers would offer me performance benefits and control that I would not be able to achieve if I used vector-based rendering techniques. When I say &#8220;vector-based&#8221; I mean rendering Shapes on a Canvas. &#8220;Pixel-based&#8221; refers to me using a DrawingContext to draw shapes in a fashion similar to how things were done in the ol&#8217; GDI+ days. I&#8217;ve left my old post in tact if you want to see how the pixel-based technique was done. Assumption aside, using pixel-based rendering has some consequences when a ScaleTransform gets applied to my control. Basically, things get blurry. It&#8217;s the same as resizing an image in Photoshop (that is, in the real world, where we don&#8217;t have CSI-like &#8220;enhance&#8221; commands). Since I&#8217;m a <a href="http://inchoatethoughts.com/scaling-your-user-interface-in-a-wpf-application">big proponent</a> of using ScaleTransforms to &#8220;zoom&#8221; in on a Window&#8217;s content as the Window resizes, I felt like this inadequacy in my control was eating away at my soul.</p>
<p>To set about changing this, I had to first mentally break down the control into vector components. Luckily, the Spectrum Analyzer isn&#8217;t terribly complex. It&#8217;s essentially a variable number of rectangles laid out horizontally. Then, added to that, is another set of rectangles (of the same quantity) that make up the &#8220;falling peaks.&#8221; </p>
<div id="attachment_477" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/ScalingSpectrum.png" target="_blank"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/03/ScalingSpectrum-300x114.png" alt="Spectrum Analyzer - Now With Vector Scaling Support!" title="Spectrum Analyzer - Now With Vector Scaling Support!" width="300" height="114" class="size-medium wp-image-477" /></a><p class="wp-caption-text">Spectrum Analyzer - Now With Vector Scaling Support!</p></div>
<p><strong>Template Support</strong></p>
<p>This brings us to crafting the control as an ACTUAL Control rather than a UserControl. Really, the only component I require is a Canvas on which I can draw all these Rectangles. I&#8217;ve set up my Control using the conventional &#8220;PART_&#8221; naming convention (see <a href="http://msdn.microsoft.com/en-us/library/system.windows.templatepartattribute.aspx">TemplatePartAttribute</a>). To actually get the bars or falling peaks to draw, an application author will also need to define the BarStyle and/or PeakStyle dependency properties on the control.  Without these, they&#8217;ll still technically &#8220;draw,&#8221; but they&#8217;ll have no brush and be invisible.</p>
<p>Here&#8217;s an example of a style and template for the SpectrumAnalyzer control.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;LinearGradientBrush x:Key=&quot;SpectrumBarBrush&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EndPoint=&quot;0.5,1&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StartPoint=&quot;0.5,0&quot;&gt;<br />
&nbsp; &nbsp; &lt;GradientStop Color=&quot;#06799F&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Offset=&quot;0&quot; /&gt;<br />
&nbsp; &nbsp; &lt;GradientStop Color=&quot;#024E68&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Offset=&quot;1&quot; /&gt;<br />
&lt;/LinearGradientBrush&gt;<br />
<br />
&lt;SolidColorBrush x:Key=&quot;SpectrumPeakBrush&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Color=&quot;#61B4CF&quot; /&gt;<br />
<br />
&lt;Style TargetType=&quot;{x:Type local:SpectrumAnalyzer}&quot;&gt;<br />
&nbsp; &nbsp; &lt;Setter Property=&quot;BarCount&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;32&quot; /&gt;<br />
&nbsp; &nbsp; &lt;Setter Property=&quot;BarSpacing&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;5&quot; /&gt;<br />
&nbsp; &nbsp; &lt;Setter Property=&quot;BarStyle&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter.Value&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Style TargetType=&quot;{x:Type Rectangle}&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;Fill&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;{StaticResource SpectrumBarBrush}&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;RadiusX&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;3&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;RadiusY&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;3&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/Style&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Setter.Value&gt;<br />
&nbsp; &nbsp; &lt;/Setter&gt;<br />
&nbsp; &nbsp; &lt;Setter Property=&quot;PeakStyle&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter.Value&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Style TargetType=&quot;{x:Type Rectangle}&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;Fill&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;{StaticResource SpectrumPeakBrush}&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;RadiusX&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;3&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter Property=&quot;RadiusY&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value=&quot;3&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/Style&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Setter.Value&gt;<br />
&nbsp; &nbsp; &lt;/Setter&gt;<br />
&nbsp; &nbsp; &lt;Setter Property=&quot;Template&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Setter.Value&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;ControlTemplate TargetType=&quot;{x:Type local:SpectrumAnalyzer}&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;Canvas Name=&quot;PART_SpectrumCanvas&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HorizontalAlignment=&quot;Stretch&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VerticalAlignment=&quot;Stretch&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ClipToBounds=&quot;True&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/ControlTemplate&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Setter.Value&gt;<br />
&nbsp; &nbsp; &lt;/Setter&gt;<br />
&lt;/Style&gt;</div></td></tr></tbody></table></div>
<p><strong>Revised Control Code</strong><br />
I&#8217;ve revised the rendering process a bit. When I first wrote the control code, there was a render method that drew a bunch of rectangles onto a DrawingVisual. Instead of drawing directly, I now just change the coordinates/size of a bunch of rectangles that are stored as fields on the Spectrum Analyzer. I let WPF handle their rendering. Thus, my &#8220;RenderSpectrumLines&#8221; method became a &#8220;UpdateSpectrumShapes&#8221; method. Also, since this is now a control, there is no XAML to go along with it per se. However, there would be a default template for it if it were placed in a Control Library. Here&#8217;s the updated code:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br />338<br />339<br />340<br />341<br />342<br />343<br />344<br />345<br />346<br />347<br />348<br />349<br />350<br />351<br />352<br />353<br />354<br />355<br />356<br />357<br />358<br />359<br />360<br />361<br />362<br />363<br />364<br />365<br />366<br />367<br />368<br />369<br />370<br />371<br />372<br />373<br />374<br />375<br />376<br />377<br />378<br />379<br />380<br />381<br />382<br />383<br />384<br />385<br />386<br />387<br />388<br />389<br />390<br />391<br />392<br />393<br />394<br />395<br />396<br />397<br />398<br />399<br />400<br />401<br />402<br />403<br />404<br />405<br />406<br />407<br />408<br />409<br />410<br />411<br />412<br />413<br />414<br />415<br />416<br />417<br />418<br />419<br />420<br />421<br />422<br />423<br />424<br />425<br />426<br />427<br />428<br />429<br />430<br />431<br />432<br />433<br />434<br />435<br />436<br />437<br />438<br />439<br />440<br />441<br />442<br />443<br />444<br />445<br />446<br />447<br />448<br />449<br />450<br />451<br />452<br />453<br />454<br />455<br />456<br />457<br />458<br />459<br />460<br />461<br />462<br />463<br />464<br />465<br />466<br />467<br />468<br />469<br />470<br />471<br />472<br />473<br />474<br />475<br />476<br />477<br />478<br />479<br />480<br />481<br />482<br />483<br />484<br />485<br />486<br />487<br />488<br />489<br />490<br />491<br />492<br />493<br />494<br />495<br />496<br />497<br />498<br />499<br />500<br />501<br />502<br />503<br />504<br />505<br />506<br />507<br />508<br />509<br />510<br />511<br />512<br />513<br />514<br />515<br />516<br />517<br />518<br />519<br />520<br />521<br />522<br />523<br />524<br />525<br />526<br />527<br />528<br />529<br />530<br />531<br />532<br />533<br />534<br />535<br />536<br />537<br />538<br />539<br />540<br />541<br />542<br />543<br />544<br />545<br />546<br />547<br />548<br />549<br />550<br />551<br />552<br />553<br />554<br />555<br />556<br />557<br />558<br />559<br />560<br />561<br />562<br />563<br />564<br />565<br />566<br />567<br />568<br />569<br />570<br />571<br />572<br />573<br />574<br />575<br />576<br />577<br />578<br />579<br />580<br />581<br />582<br />583<br />584<br />585<br />586<br />587<br />588<br />589<br />590<br />591<br />592<br />593<br />594<br />595<br />596<br />597<br />598<br />599<br />600<br />601<br />602<br />603<br />604<br />605<br />606<br />607<br />608<br />609<br />610<br />611<br />612<br />613<br />614<br />615<br />616<br />617<br />618<br />619<br />620<br />621<br />622<br />623<br />624<br />625<br />626<br />627<br />628<br />629<br />630<br />631<br />632<br />633<br />634<br />635<br />636<br />637<br />638<br />639<br />640<br />641<br />642<br />643<br />644<br />645<br />646<br />647<br />648<br />649<br />650<br />651<br />652<br />653<br />654<br />655<br />656<br />657<br />658<br />659<br />660<br />661<br />662<br />663<br />664<br />665<br />666<br />667<br />668<br />669<br />670<br />671<br />672<br />673<br />674<br />675<br />676<br />677<br />678<br />679<br />680<br />681<br />682<br />683<br />684<br />685<br />686<br />687<br />688<br />689<br />690<br />691<br />692<br />693<br />694<br />695<br />696<br />697<br />698<br />699<br />700<br />701<br />702<br />703<br />704<br />705<br />706<br />707<br />708<br />709<br />710<br />711<br />712<br />713<br />714<br />715<br />716<br />717<br />718<br />719<br />720<br />721<br />722<br />723<br />724<br />725<br />726<br />727<br />728<br />729<br />730<br />731<br />732<br />733<br />734<br />735<br />736<br />737<br />738<br />739<br />740<br />741<br />742<br />743<br />744<br />745<br />746<br />747<br />748<br />749<br />750<br />751<br />752<br />753<br />754<br />755<br />756<br />757<br />758<br />759<br />760<br />761<br />762<br />763<br />764<br />765<br />766<br />767<br />768<br />769<br />770<br />771<br />772<br />773<br />774<br />775<br />776<br />777<br />778<br />779<br />780<br />781<br />782<br />783<br />784<br />785<br />786<br />787<br />788<br />789<br />790<br />791<br />792<br />793<br />794<br />795<br />796<br />797<br />798<br />799<br />800<br />801<br />802<br />803<br />804<br />805<br />806<br />807<br />808<br />809<br />810<br />811<br />812<br />813<br />814<br />815<br />816<br />817<br />818<br />819<br />820<br />821<br />822<br />823<br />824<br />825<br />826<br />827<br />828<br />829<br />830<br />831<br />832<br />833<br />834<br />835<br />836<br />837<br />838<br />839<br />840<br />841<br />842<br />843<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#91;</span>TemplatePart<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;PART_SpectrumCanvas&quot;</span>, Type <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Canvas<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> &nbsp; &nbsp; <br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SpectrumAnalyzer <span style="color: #008000;">:</span> Control<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#region Fields</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DispatcherTimer animationTimer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> Canvas spectrumCanvas<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> ISpectrumPlayer soundPlayer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> List<span style="color: #008000;">&lt;</span>Shape<span style="color: #008000;">&gt;</span> barShapes <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>Shape<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> List<span style="color: #008000;">&lt;</span>Shape<span style="color: #008000;">&gt;</span> peakShapes <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>Shape<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> barHeights<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> peakHeights<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> channelData <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2048</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> channelPeakData<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> bandWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1.0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> barWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> maximumFrequencyIndex <span style="color: #008000;">=</span> <span style="color: #FF0000;">2047</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> minimumFrequencyIndex<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> barIndexMax<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> barLogScaleIndexMax<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Constants</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> scaleFactorLinear <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> scaleFactorSqr <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> minDBValue <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">90</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> maxDBValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> dbScale <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>maxDBValue <span style="color: #008000;">-</span> minDBValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Dependency Properties</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#region MaximumFrequency</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty MaximumFrequencyProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MaximumFrequency&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20000</span>, OnMaximumFrequencyChanged, OnCoerceMaximumFrequency<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceMaximumFrequency<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceMaximumFrequency</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnMaximumFrequencyChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnMaximumFrequencyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">int</span> OnCoerceMaximumFrequency<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value <span style="color: #008000;">&lt;</span> MinimumFrequency<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> MinimumFrequency <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnMaximumFrequencyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> oldValue, <span style="color: #6666cc; font-weight: bold;">int</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The maximum display frequency (right side) for the spectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;In usual practice, this value should be somewhere between 0 and half of the maximum sample rate. If using</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// the maximum sample rate, this would be roughly 22000.&lt;/remarks&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> MaximumFrequency<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>MaximumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>MaximumFrequencyProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Minimum Frequency</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty MinimumFrequencyProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MinimumFrequency&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span>, OnMinimumFrequencyChanged, OnCoerceMinimumFrequency<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceMinimumFrequency<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceMinimumFrequency</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnMinimumFrequencyChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnMinimumFrequencyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">int</span> OnCoerceMinimumFrequency<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CoerceValue<span style="color: #008000;">&#40;</span>MaximumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnMinimumFrequencyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> oldValue, <span style="color: #6666cc; font-weight: bold;">int</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The minimum display frequency (left side) for the spectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> MinimumFrequency<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>MinimumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>MinimumFrequencyProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region BarCount</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarCountProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarCount&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">32</span>, OnBarCountChanged, OnCoerceBarCount<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceBarCount<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceBarCount</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarCountChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnBarCountChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">int</span> OnCoerceBarCount<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>value, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarCountChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> oldValue, <span style="color: #6666cc; font-weight: bold;">int</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The number of bars to show on the sprectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;A bar's width can be a minimum of 1 pixel. If the BarSpacing and BarCount property result</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// in the bars being wider than the chart itself, the BarCount will automatically scale down.&lt;/remarks&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> BarCount<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarCountProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarCountProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region BarSpacing</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarSpacingProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarSpacing&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span>5<span style="color: #008000;">.</span>0d, OnBarSpacingChanged, OnCoerceBarSpacing<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceBarSpacing<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceBarSpacing</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarSpacingChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnBarSpacingChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">double</span> OnCoerceBarSpacing<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>value, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarSpacingChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> oldValue, <span style="color: #6666cc; font-weight: bold;">double</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The spacing, in pixels, between the bars.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> BarSpacing<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarSpacingProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarSpacingProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region PeakFallDelay</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty PeakFallDelayProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PeakFallDelay&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">10</span>, OnPeakFallDelayChanged, OnCoercePeakFallDelay<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoercePeakFallDelay<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoercePeakFallDelay</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPeakFallDelayChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnPeakFallDelayChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">int</span> OnCoercePeakFallDelay<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>value, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPeakFallDelayChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> oldValue, <span style="color: #6666cc; font-weight: bold;">int</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The delay factor for the peaks falling. This is relative to the</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// refresh rate of the chart.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> PeakFallDelay<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>PeakFallDelayProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>PeakFallDelayProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region IsFrequencyScaleLinear</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty IsFrequencyScaleLinearProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;IsFrequencyScaleLinear&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span>, OnIsFrequencyScaleLinearChanged, OnCoerceIsFrequencyScaleLinear<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceIsFrequencyScaleLinear<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceIsFrequencyScaleLinear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnIsFrequencyScaleLinearChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnIsFrequencyScaleLinearChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">bool</span> OnCoerceIsFrequencyScaleLinear<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnIsFrequencyScaleLinearChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span> oldValue, <span style="color: #6666cc; font-weight: bold;">bool</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, the bars will represent frequency buckets on a linear scale (making them all</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// have equal band widths on the frequency scale). Otherwise, the bars will be layed out</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// on a logrithmic scale, with each bar having a larger bandwidth than the one previous.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsFrequencyScaleLinear<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>IsFrequencyScaleLinearProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>IsFrequencyScaleLinearProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region BarHeightScaling</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarHeightScalingProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarHeightScaling&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">Decibel</span>, OnBarHeightScalingChanged, OnCoerceBarHeightScaling<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceBarHeightScaling<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceBarHeightScaling</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarHeightScalingChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnBarHeightScalingChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> BarHeightScalingStyles OnCoerceBarHeightScaling<span style="color: #008000;">&#40;</span>BarHeightScalingStyles value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarHeightScalingChanged<span style="color: #008000;">&#40;</span>BarHeightScalingStyles oldValue, BarHeightScalingStyles newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, the bar height will be displayed linearly with the intensity value.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Otherwise, the bars will be scaled with a square root function.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> BarHeightScalingStyles BarHeightScaling<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>BarHeightScalingStyles<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarHeightScalingProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarHeightScalingProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region AveragePeaks</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty AveragePeaksProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;AveragePeaks&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span>, OnAveragePeaksChanged, OnCoerceAveragePeaks<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceAveragePeaks<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceAveragePeaks</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnAveragePeaksChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnAveragePeaksChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">bool</span> OnCoerceAveragePeaks<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnAveragePeaksChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span> oldValue, <span style="color: #6666cc; font-weight: bold;">bool</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, each bar's peak value will be averaged with the previous</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// bar's peak. This creates a smoothing effect on the bars.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AveragePeaks<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>AveragePeaksProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>AveragePeaksProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region BarStyle</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarStyleProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarStyle&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyChangedCallback<span style="color: #008000;">&#40;</span>OnBarStyleChanged<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>OnCoerceBarStyle<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceBarStyle<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceBarStyle</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarStyleChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnBarStyleChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> Style OnCoerceBarStyle<span style="color: #008000;">&#40;</span>Style value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnBarStyleChanged<span style="color: #008000;">&#40;</span>Style oldValue, Style newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// A style with which to draw the bars on the spectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Style BarStyle<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarStyleProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarStyleProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region PeakStyle</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty PeakStyleProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PeakStyle&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyChangedCallback<span style="color: #008000;">&#40;</span>OnPeakStyleChanged<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>OnCoercePeakStyle<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoercePeakStyle<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoercePeakStyle</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPeakStyleChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnPeakStyleChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> Style OnCoercePeakStyle<span style="color: #008000;">&#40;</span>Style value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPeakStyleChanged<span style="color: #008000;">&#40;</span>Style oldValue, Style newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// A style with which to draw the falling peaks on the spectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Style PeakStyle<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>Style<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>PeakStyleProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>PeakStyleProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region ActualBarWidth</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ActualBarWidthProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ActualBarWidth&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span>0<span style="color: #008000;">.</span>0d, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyChangedCallback<span style="color: #008000;">&#40;</span>OnActualBarWidthChanged<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>OnCoerceActualBarWidth<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceActualBarWidth<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceActualBarWidth</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnActualBarWidthChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> SpectrumAnalyzer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spectrumAnalyzer <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">OnActualBarWidthChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">double</span> OnCoerceActualBarWidth<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnActualBarWidthChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> oldValue, <span style="color: #6666cc; font-weight: bold;">double</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The actual width that the bars will be drawn at.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> ActualBarWidth<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>ActualBarWidthProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>ActualBarWidthProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Enums</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The different ways that the bar height can be scaled by the spectrum analyzer.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> BarHeightScalingStyles<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// A decibel scale. Formula: 20 * Log10(FFTValue). Total bar height</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// is scaled from -90 to 0 dB.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Decibel,<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// A non-linear squareroot scale. Formula: Sqrt(FFTValue) * 2 * BarHeight.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Sqrt,<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// A linear scale. Formula: 9 * FFTValue * BarHeight.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Linear<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The styles that the spectrum analyzer can draw the bars.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> BarDrawingStyles<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Square bars.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Square,<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Rounded bars with the corner radius as half the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// bar width.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Rounded<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Template Overrides</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnApplyTemplate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; spectrumCanvas <span style="color: #008000;">=</span> GetTemplateChild<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PART_SpectrumCanvas&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Canvas<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Constructors</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> SpectrumAnalyzer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DefaultStyleKeyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">OverrideMetadata</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> SpectrumAnalyzer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; animationTimer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DispatcherTimer<span style="color: #008000;">&#40;</span>DispatcherPriority<span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationIdle</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Interval <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">25</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Tick</span> <span style="color: #008000;">+=</span> animationTimer_Tick<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Public Methods</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Register a sound player from which the spectrum analyzer</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// can get the necessary playback data.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;soundPlayer&quot;&gt;A sound player that provides spectrum data through the ISpectrumPlayer interface methods.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> RegisterSoundPlayer<span style="color: #008000;">&#40;</span>ISpectrumPlayer soundPlayer<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">soundPlayer</span> <span style="color: #008000;">=</span> soundPlayer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> soundPlayer_PropertyChanged<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Event Overrides</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRender<span style="color: #008000;">&#40;</span>DrawingContext dc<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnRender</span><span style="color: #008000;">&#40;</span>dc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRenderSizeChanged<span style="color: #008000;">&#40;</span>SizeChangedInfo sizeInfo<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnRenderSizeChanged</span><span style="color: #008000;">&#40;</span>sizeInfo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Private Drawing Methods</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>soundPlayer <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> spectrumCanvas <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPlaying</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFFTData</span><span style="color: #008000;">&#40;</span>channelData<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrumShapes<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateSpectrumShapes<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">bool</span> allZero <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> fftBucketHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> lastPeakHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> peakYPos <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> height <span style="color: #008000;">=</span> spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> barIndex <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> peakDotHeight <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">/</span> 2<span style="color: #008000;">.</span>0f, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> barHeightScale <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> peakDotHeight<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> minimumFrequencyIndex<span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> maximumFrequencyIndex<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If we're paused, keep drawing, but set the current height to 0 so the peaks fall.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPlaying</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// Draw the maximum value for the bar's band</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>BarHeightScaling<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BarHeightScalingStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">Decibel</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> dbValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span> <span style="color: #008000;">*</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log10</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>channelData<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>dbValue <span style="color: #008000;">-</span> minDBValue<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> dbScale<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BarHeightScalingStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">Linear</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>channelData<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">*</span> scaleFactorLinear<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BarHeightScalingStyles<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>channelData<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> scaleFactorSqr<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&lt;</span> fftBucketHeight<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> fftBucketHeight<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&lt;</span> 0f<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If this is the last FFT bucket in the bar's group, draw the bar.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> currentIndexMax <span style="color: #008000;">=</span> IsFrequencyScaleLinear <span style="color: #008000;">?</span> barIndexMax<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">:</span> barLogScaleIndexMax<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">==</span> currentIndexMax<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Peaks can't surpass the height of the control.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&gt;</span> height<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> height<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>AveragePeaks <span style="color: #008000;">&amp;&amp;</span> barIndex <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>lastPeakHeight <span style="color: #008000;">+</span> barHeight<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakYPos <span style="color: #008000;">=</span> barHeight<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">&lt;</span> peakYPos<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>peakYPos<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>peakYPos <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>PeakFallDelay <span style="color: #008000;">*</span> channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>PeakFallDelay <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> xCoord <span style="color: #008000;">=</span> BarSpacing <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">*</span> barIndex<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>BarSpacing <span style="color: #008000;">*</span> barIndex<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barShapes<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Margin</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #008000;">&#40;</span>xCoord, <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> barHeight, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barShapes<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> barHeight<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakShapes<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Margin</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #008000;">&#40;</span>xCoord, <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">-</span> peakDotHeight, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakShapes<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> peakDotHeight<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0.05</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allZero <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lastPeakHeight <span style="color: #008000;">=</span> barHeight<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barIndex<span style="color: #008000;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>allZero <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPlaying</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateBarLayout<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>soundPlayer <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> spectrumCanvas <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; barWidth <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> <span style="color: #008000;">&#40;</span>BarSpacing <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>BarCount <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>BarCount<span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; maximumFrequencyIndex <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFFTFrequencyIndex</span><span style="color: #008000;">&#40;</span>MaximumFrequency<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">2047</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; minimumFrequencyIndex <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFFTFrequencyIndex</span><span style="color: #008000;">&#40;</span>MinimumFrequency<span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">2047</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bandWidth <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex <span style="color: #008000;">-</span> minimumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span>, <span style="color: #FF0000;">1.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> actualBarCount<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">&gt;=</span> 1<span style="color: #008000;">.</span>0d<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; actualBarCount <span style="color: #008000;">=</span> BarCount<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; actualBarCount <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> BarSpacing<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">+</span> BarSpacing<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; channelPeakData <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span>actualBarCount<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> indexCount <span style="color: #008000;">=</span> maximumFrequencyIndex <span style="color: #008000;">-</span> minimumFrequencyIndex<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> linearIndexBucketSize <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Round</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>indexCount <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>actualBarCount, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> maxIndexList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> maxLogScaleIndexList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> maxLog <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>actualBarCount, actualBarCount<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> actualBarCount<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>minimumFrequencyIndex <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> linearIndexBucketSize<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> logIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>maxLog <span style="color: #008000;">-</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>actualBarCount <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> i, <span style="color: #008000;">&#40;</span>actualBarCount <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> indexCount<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> minimumFrequencyIndex<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>logIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; barIndexMax <span style="color: #008000;">=</span> maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; barLogScaleIndexMax <span style="color: #008000;">=</span> maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; barHeights <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#91;</span>actualBarCount<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; peakHeights <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#91;</span>actualBarCount<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; barShapes<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; peakShapes<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> height <span style="color: #008000;">=</span> spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> peakDotHeight <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">/</span> 2<span style="color: #008000;">.</span>0f, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> actualBarCount<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> xCoord <span style="color: #008000;">=</span> BarSpacing <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">*</span> i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>BarSpacing <span style="color: #008000;">*</span> i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rectangle barRectangle <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Margin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #008000;">&#40;</span>xCoord, height, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width <span style="color: #008000;">=</span> barWidth,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Style <span style="color: #008000;">=</span> BarStyle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barShapes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>barRectangle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rectangle peakRectangle <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Margin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thickness<span style="color: #008000;">&#40;</span>xCoord, height <span style="color: #008000;">-</span> peakDotHeight, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width <span style="color: #008000;">=</span> barWidth,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height <span style="color: #008000;">=</span> peakDotHeight,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Style <span style="color: #008000;">=</span> PeakStyle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakShapes<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>peakRectangle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Shape shape <span style="color: #0600FF; font-weight: bold;">in</span> barShapes<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>shape<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Shape shape <span style="color: #0600FF; font-weight: bold;">in</span> peakShapes<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>shape<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ActualBarWidth <span style="color: #008000;">=</span> barWidth<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Event Handlers</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> soundPlayer_PropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, PropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyName</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #666666;">&quot;IsPlaying&quot;</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>soundPlayer<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPlaying</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">IsEnabled</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> animationTimer_Tick<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>On Performance / Conclusion</strong><br />
So, where does this leave us? A peak at the Task Manager delivers a pretty telling tale. On my system, the control continues to use very little processor power. What&#8217;s even better, however, is you&#8217;ll see far less churning of the memory usage. It seems that when you let WPF handle the rendering, it gets to have better control of what sort of buffers get created and how quickly they&#8217;re cleared from memory. When we did it manually with our RenderTargetBitmap, we were at the mercy of the garbage collector.</p>
<p>I think there are still a number of controls where one will need to fall back on to pixel based rendering (e.g., a spectrogram), but this one lent itself well to being drawn with vectors. That said, I think the current iteration of this Control is far closer to how one should design their controls for other people to use. People incorporating this into their own applications should find it much more flexible in style, as well as much more performant. </p>
<p><strong><a href="http://inchoatethoughts.com/uploads/WPFSpectrumAnalyzer.zip" target="_blank">Download Source Code</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Scaling Your User Interface in a WPF Application</title>
		<link>http://inchoatethoughts.com/scaling-your-user-interface-in-a-wpf-application</link>
		<comments>http://inchoatethoughts.com/scaling-your-user-interface-in-a-wpf-application#comments</comments>
		<pubDate>Sun, 13 Mar 2011 23:28:09 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[LayoutTransform]]></category>
		<category><![CDATA[ScaleTransform]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=426</guid>
		<description><![CDATA[A few years back, we were demonstrating a WinForms application we&#8217;d just spent a few years developing to the Vice President of the R&#38;D department. Things were starting to come together and look really nice. Many tough battles were fought to develop custom real-time controls and get everything laid out properly. Months, to years, of [...]]]></description>
			<content:encoded><![CDATA[<p>A few years back, we were demonstrating a WinForms application we&#8217;d just spent a few years developing to the Vice President of the R&amp;D department. Things were starting to come together and look really nice. Many tough battles were fought to develop custom real-time controls and get everything laid out properly. Months, to years, of effort went into choosing colors and gradients that were easy on the eyes. Hell, we&#8217;d even gone out of our way to get in decent support for higher, non-default DPI settings. All-in-all, we were pretty proud of the UX for this application. So, the VP was sitting there, toying around with the application. Then he maximizes the window. The application does exactly what it is supposed to. It fills up all 26 inches of his fancy high-resolution monitor. Everything is docked properly, so the main datagrid on the form expands both vertically and horizontally. The Ribbon Bar at the top of the application keeps its height and the navigation pane on the side keeps its width. Everything seems to be going well.<br />
<div id="attachment_441" class="wp-caption alignright" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowNoStretch.png"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowNoStretch-300x251.png" alt="Our window at normal size" title="WOur window at normal size" width="300" height="251" class="size-medium wp-image-441" /></a><p class="wp-caption-text">Our window at normal size</p></div><br />
The VP then asks a fairly innocuous question that really drives home why WinForms is obsolete on modern displays. He asks something along the lines of &#8220;why is it that when I maximize this window, things don&#8217;t get bigger?&#8221; We&#8217;re a little confused and reply, &#8220;Things did get bigger. As you can see, the data grid grew.&#8221; He retorts &#8220;No, no. There is more data on the screen, but all of the fonts and everything stay the same size. It&#8217;d be nice if things got *bigger* so they were easier to read on these really high-resolution monitors.&#8221; Now, if any of you have ever attempted to deal with this sort of request in WinForms, you&#8217;ll understand exactly why this is VERY hard to achieve. WinForms is pixel-based and very much resolution-dependent. Fulfilling the request to have things zoom/scale in WinForms falls somewhere just short of impossible. It would certainly take a massive amount of infrastructure coding to do this with much success, and forget about using a third-party control library (or even the standard set of controls).<br />
<div id="attachment_445" class="wp-caption alignleft" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowStretch-Old.png"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowStretch-Old-300x216.png" alt="Stretching our window using the traditional scaling techniques" title="Stretching our window using the traditional scaling techniques" width="300" height="216" class="size-medium wp-image-445" /></a><p class="wp-caption-text">Stretching our window using the traditional scaling techniques</p></div><br />
Luckily, our VP wasn&#8217;t the only person in the world to have this request. Microsoft noted this issue and seems to have built WPF around this very problem. However, it intrigues me that more people have not seemed to clue in on this new way of scaling their application&#8217;s Window. I&#8217;ve seen it out there, but only in about of a quarter of the WPF applications I&#8217;ve tried. I think either people aren&#8217;t aware of this new method or don&#8217;t know of a nice, robust way to implement it so that simply resizing the Window causes your UI elements to scale-up.</p>
<p><strong>Implementing Scaling</strong></p>
<p>At the heart of this scaling solution, there are two concepts at work. First, there is a LayoutTransform that will be applied at very root-most content element of your Window. Secondly, there will be some resize-detection logic in the Window  to determine what sort of scaling needs to happen.<br />
<div id="attachment_446" class="wp-caption alignright" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowStretch-New.png"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/03/WindowStretch-New-300x216.png" alt="Stretching our window using WPF&#039;s ScaleTransform - note the relative size of the window&#039;s title bar" title="Stretching our window using WPF&#039;s ScaleTransform - note the relative size of the window&#039;s title bar" width="300" height="216" class="size-medium wp-image-446" /></a><p class="wp-caption-text">Stretching our window using WPF&#039;s ScaleTransform - note the relative size of the window&#039;s title bar</p></div><br />
First, we&#8217;ll start with the XAML where we define the LayoutTransform. Give your main grid a name (or whatever your root element is: border, etc.). Also hook up its SizeChanged event. We&#8217;ll come back to that. It&#8217;ll be important to also define a minimum width and height for the form, as scaling it too small will make it impossible to read. In the LayoutTransform, define a ScaleTransform. This ScaleTransform will have the ScaleX and ScaleY value uniformly bound to the certain ScaleValue. The ScaleValue will be essentially the percentage of zoom we&#8217;ll employ. If that value is 1.2, you can expect your controls to be zoomed in at 120%. To phrase it another way, we&#8217;re attempting to zoom-to-fill all of our contents before attempting to refactor our layout using the docking configuration.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;Window x:Class=&quot;WpfApplication1.MainWindow&quot;<br />
&nbsp; &nbsp; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br />
&nbsp; &nbsp; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br />
&nbsp; &nbsp; Title=&quot;MainWindow&quot; <br />
&nbsp; &nbsp; Name=&quot;myMainWindow&quot;<br />
&nbsp; &nbsp; Width=&quot;500&quot; <br />
&nbsp; &nbsp; Height=&quot;400&quot;<br />
&nbsp; &nbsp; MinWidth=&quot;250&quot; <br />
&nbsp; &nbsp; MinHeight=&quot;200&quot;&gt;<br />
&lt;Grid Name=&quot;MainGrid&quot; SizeChanged=&quot;MainGrid_SizeChanged&quot;&gt;<br />
&nbsp; &nbsp; &lt;Grid.LayoutTransform&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;ScaleTransform x:Name=&quot;ApplicationScaleTransform&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CenterX=&quot;0&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CenterY=&quot;0&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScaleX=&quot;{Binding ElementName=myMainWindow, Path=ScaleValue}&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScaleY=&quot;{Binding ElementName=myMainWindow, Path=ScaleValue}&quot; /&gt;<br />
&nbsp; &nbsp; &lt;/Grid.LayoutTransform&gt;<br />
&nbsp; &nbsp; &lt;!-- Window Content Here --&gt;<br />
&lt;/Grid&gt;</div></td></tr></tbody></table></div>
<p>Now, in the code-behind, we&#8217;ll be creating a ScaleValue dependency property for the ScaleTransform to bind to. This ScaleValue is set whenever the size of the Window changes. The value is calculated based on the current width or height divided by the designed-for width or height. We take the lower of those two values and make that our scaling mechanism. This makes the zoom effect similar to what you&#8217;re used to seeing when you use a Viewbox when the StretchDirection is &#8220;Both&#8221; and the Stretch style is &#8220;Fill.&#8221;</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MainWindow <span style="color: #008000;">:</span> Window<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#region ScaleValue Depdency Property</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ScaleValueProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ScaleValue&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>MainWindow<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1.0</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PropertyChangedCallback<span style="color: #008000;">&#40;</span>OnScaleValueChanged<span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>OnCoerceScaleValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> OnCoerceScaleValue<span style="color: #008000;">&#40;</span>DependencyObject o, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MainWindow mainWindow <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> MainWindow<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>mainWindow <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> mainWindow<span style="color: #008000;">.</span><span style="color: #0000FF;">OnCoerceScaleValue</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnScaleValueChanged<span style="color: #008000;">&#40;</span>DependencyObject o, DependencyPropertyChangedEventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MainWindow mainWindow <span style="color: #008000;">=</span> o <span style="color: #0600FF; font-weight: bold;">as</span> MainWindow<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>mainWindow <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainWindow<span style="color: #008000;">.</span><span style="color: #0000FF;">OnScaleValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">OldValue</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NewValue</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">double</span> OnCoerceScaleValue<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNaN</span><span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> 1<span style="color: #008000;">.</span>0d<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0.1</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnScaleValueChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> oldValue, <span style="color: #6666cc; font-weight: bold;">double</span> newValue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> ScaleValue<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>ScaleValueProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>ScaleValueProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> MainGrid_SizeChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CalculateScale<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CalculateScale<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> yScale <span style="color: #008000;">=</span> ActualHeight <span style="color: #008000;">/</span> 400<span style="color: #008000;">.</span>0d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> xScale <span style="color: #008000;">=</span> ActualWidth <span style="color: #008000;">/</span> 500<span style="color: #008000;">.</span>0d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> value <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>xScale, yScale<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ScaleValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>OnCoerceScaleValue<span style="color: #008000;">&#40;</span>MainGrid, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> MainWindow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s all there is to it! Beyond increasing the size of your Window, it works surprisingly well when decreasing the window size too, down to a certain level anyway. I find this solution to be robust enough to handle most cases my application, but be sure to read over the next section to understand some caveats.</p>
<p><strong>Caveats</strong></p>
<p>ScaleTransform can cause problems if any of your UI elements are rendered using pixel-based rendering techniques. What happens? Well, when you scale, the bitmap buffers of the controls start to stretch and appear blurry. Luckily, in my experience, very few third party components that were designed for WPF do this kind of pixel-based rendering. Kudos to the majority of WPF control developers for doing things the recommended way. In your own controls, there are a few key areas you need to be aware of where this can be problematic:</p>
<ol>
<li>Controls that use the new CacheMode property.</li>
<li>Controls that use DrawingVisuals, RenderTargetBitmap or WriteableBitmap, and DrawingContext to draw.</li>
<li>Use of WinForms components in your WPF application.</li>
</ol>
<p><strong>Dealing With The Caveats</strong></p>
<p><strong>CacheMode</strong>: To deal with CacheMode when scaling, you can try using the RenderAtScale property. I do this semi-automatically on my custom controls by including a mechanism to automatically detect what ScaleTransform has been applied to the control. Then, I make the RenderAtScale property the same. I include a &#8220;UseAutoScaling&#8221; property to allow the control&#8217;s user to decide whether or not they want to have this behavior happen in their Application.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRenderSizeChanged<span style="color: #008000;">&#40;</span>SizeChangedInfo sizeInfo<span style="color: #008000;">&#41;</span><br />
&nbsp;<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnRenderSizeChanged</span><span style="color: #008000;">&#40;</span>sizeInfo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UpdateCacheScaling<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateCacheScaling<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>myCanvas <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; BitmapCache cache <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>BitmapCache<span style="color: #008000;">&#41;</span>myCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">CacheMode</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>UseAutoScaling<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> totalTransformScale <span style="color: #008000;">=</span> GetTotalTransformScale<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>cache<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderAtScale</span> <span style="color: #008000;">!=</span> totalTransformScale<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderAtScale</span> <span style="color: #008000;">=</span> totalTransformScale<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cache<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderAtScale</span> <span style="color: #008000;">=</span> 1<span style="color: #008000;">.</span>0d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> GetTotalTransformScale<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> totalTransform <span style="color: #008000;">=</span> 1<span style="color: #008000;">.</span>0d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; DependencyObject currentVisualTreeElement <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Visual visual <span style="color: #008000;">=</span> currentVisualTreeElement <span style="color: #0600FF; font-weight: bold;">as</span> Visual<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>visual <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Transform transform <span style="color: #008000;">=</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTransform</span><span style="color: #008000;">&#40;</span>visual<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// This condition is a way of determining if it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// was a uniform scale transform. Is there some better way?</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>transform <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">M12</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">M21</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OffsetX</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OffsetY</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">M11</span> <span style="color: #008000;">==</span> transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">M22</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalTransform <span style="color: #008000;">*=</span> transform<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">M11</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentVisualTreeElement <span style="color: #008000;">=</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetParent</span><span style="color: #008000;">&#40;</span>currentVisualTreeElement<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>currentVisualTreeElement <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> totalTransform<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>RenderTargetBitmap or WriteableBitmap</strong>: I have found no great solution for this. If the control is being drawn using these techniques, the only option is to alter the code such that it renders at a higher scale or change it dramatically to use vector-based drawing. Be aware that even if the control is tricked into drawing at a higher resolution, if it is being rendered to an Image, it will still appear blurry. The scale of the Image will also have to dealt with.</p>
<p><strong>WinForms Controls</strong>: Stop using WinForms controls! No seriously, you&#8217;re killing your application&#8217;s memory usage and performance by dropping these into your WPF application.</p>
<p>I hope this gives you all a starting point to making your WPF application scale. It&#8217;d be really nice if more applications featured this ability, even if as a user-preference.</p>
<p><a href="http://inchoatethoughts.com/uploads/ScalingExample.zip">Download Sample Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/scaling-your-user-interface-in-a-wpf-application/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XAML Regions: A Visual Studio 2010 Extension</title>
		<link>http://inchoatethoughts.com/xamlregions</link>
		<comments>http://inchoatethoughts.com/xamlregions#comments</comments>
		<pubDate>Tue, 01 Mar 2011 13:43:16 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Regions]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VSIX]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=386</guid>
		<description><![CDATA[If you&#8217;re like me, dealing with giant XAML files is problematic. I don&#8217;t seem to possess the mental stack that some XAMLers have that allows them to deal with pages upon pages of disorganized XAML code. I frequently run into this dilemma when I deal with WPF themes. They&#8217;re usually colors, brushes, styles and templates [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, dealing with giant XAML files is problematic. I don&#8217;t seem to possess the mental stack that some XAMLers have that allows them to deal with pages upon pages of disorganized XAML code. I frequently run into this dilemma when I deal with WPF themes. They&#8217;re usually colors, brushes, styles and templates for every single WPF control in existence all crammed into one file. I have to rely on text searches for terms like &#8220;Button&#8221; to find what I&#8217;m looking for. I found myself pleading to the markup language gods for the regioning system I had grown so accustomed to in C#. My prayers combined with my Internet searches lacked the fecundity to bare any useful results, so I was on my own. Luckily, Visual Studio 2010 has a pretty easy-to-use Extension Framework. As such, I whipped up a plugin that allows XAML regions. Like most things of this nature, I see no pressing reason to hoard it all to myself.</p>
<div id="attachment_407" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/03/XAMLRegionsBig.png" target="_blank"><img class="size-medium wp-image-407" title="XAML Regions Extension For Visual Studio 2010" src="http://inchoatethoughts.com/wp-content/uploads/2011/03/XAMLRegionsBig-300x157.png" alt="XAML Regions Extension For Visual Studio 2010" width="300" height="157" /></a><p class="wp-caption-text">XAML Regions Extension For Visual Studio 2010</p></div>
<p><strong>Using The Extension</strong></p>
<p>There&#8217;s nothing particularly complex about using this extension. I wanted to make it so that people without this extension didn&#8217;t have trouble working with code from people who did have the extension. I chose to make it so that XAML regions were defined in XML comments. One would start a XAML region by having a few lines that consist of</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!-- Region (Any Text You Want) --&gt;<br />
Your Code<br />
&lt;!-- EndRegion --&gt;</div></td></tr></tbody></table></div>
<p>Spacing, prefix hash characters, and description text are all generally optional. All of the following uses are supported:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!-- Region Hello World --&gt; <br />
Your code <br />
&lt;!-- End Region --&gt; <br />
&nbsp;<br />
&lt;!-- RegionHello World --&gt; <br />
Your code <br />
&lt;!-- EndRegion --&gt; <br />
&nbsp;<br />
&lt;!-- #Region Hello World --&gt; <br />
Your code <br />
&lt;!-- #End Region --&gt; <br />
&nbsp;<br />
&lt;!-- #Region Hello World --&gt; <br />
Your code <br />
&lt;!-- #EndRegion --&gt; <br />
&nbsp;<br />
&lt;!-- Region Hello World --&gt; <br />
Your code <br />
&lt;!-- End Region Hello World --&gt;</div></td></tr></tbody></table></div>
<p>That&#8217;s really all there is to it!<br />
<a href="http://visualstudiogallery.msdn.microsoft.com/3c534623-bb05-417f-afc0-c9e26bf0e177" target="_blank"><br />
Grab it at the Visual Studio Gallery</a></p>
<p><strong>Updated in 0.4</strong></p>
<ol>
<li>Added the ability to have hash character prefixes (e.g., &lt;!&#8211; #Region &#8211;&gt;)</li>
<li>IAdded the ability to have description text in the EndRegion area (e.g., &lt;!&#8211; End Region (Your Text) &#8211;&gt;)</li>
</ol>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/xamlregions/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>A WPF Spectrum Analyzer for Audio Visualization (C#)</title>
		<link>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization</link>
		<comments>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization#comments</comments>
		<pubDate>Sat, 29 Jan 2011 04:07:18 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[BASS]]></category>
		<category><![CDATA[BASS.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Spectrum Analyzer]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Visualizer]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=345</guid>
		<description><![CDATA[UPDATE:The WPF Spectrum Analyzer is now part of the WPF Sound Visualization Library. That is where you will find source code for the latest and most-stable versions of the Spectrum Analyzer. Also, this post has been updated and superseded by this one. I&#8217;m leaving this one here for historical purposes, but check out the other [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong>The WPF Spectrum Analyzer is now part of the <a href="http://wpfsvl.codeplex.com/" target="_blank">WPF Sound Visualization Library</a>. That is where you will find source code for the latest and most-stable versions of the Spectrum Analyzer. Also, this post has been updated and superseded by <a href="http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening">this one</a>. I&#8217;m leaving this one here for historical purposes, but <a href="http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization-c-part-2-the-wpfening">check out the other article for a more performant and scalable version the control</a>.</p>
<p>&#8212;</p>
<p>A coworker and I were recently talking about doing audio visualization with Windows Presentation Foundation (WPF). One of the more common visualization techniques for music applications is to slap in a simple banded spectrum analyzer. I thought such spectrum analyzers would be easy to find, as they&#8217;re included in many applications written in toward all sorts of platforms. A bit surprisingly, however, was that such visualizations in WPF aren&#8217;t as common as I would have expected. I thought I could use the rarity of such controls as an opportunity to play around with some fast rendering techniques in WPF. I was fairly pleased with the outcome, so I thought I would share the results.</p>
<div id="attachment_381" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/02/SpectrumAnalyzer.png" target="_blank"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/02/SpectrumAnalyzer-300x217.png" alt="The Spectrum Analyzer Control" title="The Spectrum Analyzer Control" width="300" height="217" class="size-medium wp-image-381" /></a><p class="wp-caption-text">The Spectrum Analyzer Control</p></div>
<p><strong>About Playing Audio</strong></p>
<p>If any of you have tried to do anything with audio in .NET, you&#8217;ve probably found the out-of-the-box functionality to be pretty limited. WPF has some enhancements in this area, but it is nowhere near some of the alternatives. Going the other way, one may choose to use direct references to DirectSound to get the power they need. However, this leaves it up to you, the coder, to deal with all the scaling back when the user&#8217;s machine doesn&#8217;t meet the needs. I find it much easier to use some of the third party sound APIs out there who take care of all these gritty details</p>
<p>My &#8220;sound suite&#8221; of choice is the <a href="http://www.un4seen.com/" target="_blank">BASS</a> API.  BASS is loaded with features. Along with getting sound set up to play, it also has the ability to read all sorts of file formats, do effects processing, record sound, and more. However, BASS is unmanaged. To interface BASS with .NET, one will need the aptly named <a href="http://bass.radio42.com/" target="_blank">BASS.NET</a>. At a passing glance, one may see BASS.NET as a thin .NET wrapper over the BASS API. However, it actually has some very useful additions. Benefits include tag reading support, useful methods for parsing FFT data, and even some visualizers included (but they are targeted to WinForms/GDI+). It was actually the source code for these visualizers that I used as a starting point for this WPF control. BASS.NET&#8217;s author, Bernd Niedergesaess (a.k.a radio42), was kind enough to let me share this source code with you today even though he really did all of the heavy-lifting/pioneering for this project during his development of BASS.NET.</p>
<p><strong>The Spectrum Analyzer</strong></p>
<p>Now, I&#8217;m not new to writing Spectrum Analyzers. Previous software engineering jobs had me writing controls for Windows-based Spectrum Analyzers in the past. However, these weren&#8217;t for audio visualization, but were more for scientific measurements of radio and microwave signals. One of the things I noticed about audio visualizations is that a lot of accuracy is ignored in favor of making the visualizer look and feel in line with what we perceive. I won&#8217;t go into great amounts of detail on this, but when you see funky methods being applied to FFT results in the source code, this is probably what is going on. One of the most common examples of this is that FFT data is never displayed on the Y-axis linearly, but rather using a square root function and a scaling factor. Without this, you see most of the visualizer moving very little, except for the occasional large burst of energy. This is NOT how your ears/brain perceive the sound you&#8217;re listening to.</p>
<p>So, let&#8217;s take a look at what the control looks like in XAML:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;my:SpectrumAnalyzer x:Name=&quot;spectrumAnalyzer&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Height=&quot;160&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HorizontalAlignment=&quot;Stretch&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VerticalAlignment=&quot;Bottom&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BarSpacing=&quot;5&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AveragePeaks=&quot;False&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MinimumFrequency=&quot;20&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MaximumFrequency=&quot;20000&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BarCount=&quot;32&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PeakFallDelay=&quot;10&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BarHeightScaling=&quot;Decibel&quot; /&gt;</div></td></tr></tbody></table></div>
<p>It all looks pretty straightforward. Besides the attributes I&#8217;ve shown on the control here, I also have included dependency properties to set brushes for the bars and their peaks, as well as a dependency property for the linearity of displayed channel data. Here&#8217;s the XAML for the Spectrum Analyzer control itself.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;UserControl x:Class=&quot;BandedSpectrumAnalyzer.SpectrumAnalyzer&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;<br />
&nbsp; &nbsp; &lt;Canvas&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;Image Name=&quot;SpectrumImage&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HorizontalAlignment=&quot;Stretch&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VerticalAlignment=&quot;Stretch&quot; /&gt;<br />
&nbsp; &nbsp; &lt;/Canvas&gt;<br />
&lt;/UserControl&gt;</div></td></tr></tbody></table></div>
<p>Shockingly simple, no? That&#8217;s because the meat of this control is in the code-behind. I&#8217;ve chosen to do a more classic pixel-based rendering technique for this UserControl. This is good and bad, but not the norm for WPF development. It&#8217;s good because it gives me a bit more control in terms of performance. It&#8217;s bad in that WPF is meant to be scaled freely, and now it is my responsibility to make that work well. Now, here&#8217;s where the real work happens.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br />338<br />339<br />340<br />341<br />342<br />343<br />344<br />345<br />346<br />347<br />348<br />349<br />350<br />351<br />352<br />353<br />354<br />355<br />356<br />357<br />358<br />359<br />360<br />361<br />362<br />363<br />364<br />365<br />366<br />367<br />368<br />369<br />370<br />371<br />372<br />373<br />374<br />375<br />376<br />377<br />378<br />379<br />380<br />381<br />382<br />383<br />384<br />385<br />386<br />387<br />388<br />389<br />390<br />391<br />392<br />393<br />394<br />395<br />396<br />397<br />398<br />399<br />400<br />401<br />402<br />403<br />404<br />405<br />406<br />407<br />408<br />409<br />410<br />411<br />412<br />413<br />414<br />415<br />416<br />417<br />418<br />419<br />420<br />421<br />422<br />423<br />424<br />425<br />426<br />427<br />428<br />429<br />430<br />431<br />432<br />433<br />434<br />435<br />436<br />437<br />438<br />439<br />440<br />441<br />442<br />443<br />444<br />445<br />446<br />447<br />448<br />449<br />450<br />451<br />452<br />453<br />454<br />455<br />456<br />457<br />458<br />459<br />460<br />461<br />462<br />463<br />464<br />465<br />466<br />467<br />468<br />469<br />470<br />471<br />472<br />473<br />474<br />475<br />476<br />477<br />478<br />479<br />480<br />481<br />482<br />483<br />484<br />485<br />486<br />487<br />488<br />489<br />490<br />491<br />492<br />493<br />494<br />495<br />496<br />497<br />498<br />499<br />500<br />501<br />502<br />503<br />504<br />505<br />506<br />507<br />508<br />509<br />510<br />511<br />512<br />513<br />514<br />515<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Controls</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Media</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Media.Imaging</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Windows.Threading</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Un4seen.Bass</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> BandedSpectrumAnalyzer<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Interaction logic for SpectrumAnalyzer.xaml</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> SpectrumAnalyzer <span style="color: #008000;">:</span> UserControl<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Fields</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> DispatcherTimer animationTimer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> RenderTargetBitmap anaylzerBuffer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> DrawingVisual drawingVisual <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DrawingVisual<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> channelData <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2048</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> channelPeakData<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> scaleFactorLinear <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> scaleFactorSqr <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> maxFFTData <span style="color: #008000;">=</span> <span style="color: #FF0000;">4096</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> BASSData maxFFT <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>BASSData<span style="color: #008000;">.</span><span style="color: #0000FF;">BASS_DATA_AVAILABLE</span> <span style="color: #008000;">|</span> BASSData<span style="color: #008000;">.</span><span style="color: #0000FF;">BASS_DATA_FFT4096</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> bandWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1.0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> barWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> maximumFrequencyIndex <span style="color: #008000;">=</span> <span style="color: #FF0000;">2047</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> minimumFrequencyIndex <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> sampleFrequency <span style="color: #008000;">=</span> <span style="color: #FF0000;">44100</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> barIndexMax<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> barLogScaleIndexMax<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> BassEngine bassEngine<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Dependency Property Declarations</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty MaximumFrequencyProperty<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty MinimumFrequencyProperty<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarCountProperty<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarSpacingProperty<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty PeakFallDelayProperty<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty StreamHandleProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;StreamHandle&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty FrequencyScaleIsLinearProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FrequencyScaleIsLinear&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarHeightScalingProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarHeightScaling&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>BarHeightScaling<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty AveragePeaksProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;AveragePeaks&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty BarBrushProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarBrush&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Brush<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty PeakBrushProperty <span style="color: #008000;">=</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PeakBrush&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>Brush<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Dependency Properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The maximum display frequency (right side) for the spectrum analyzer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;This value should be somewhere between 0 and half of the maximum sample rate. If using</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// the maximum sample rate, this would be roughly 22000.&lt;/remarks&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> MaximumFrequency<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>MaximumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>MaximumFrequencyProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The minimum display frequency (left side) for the spectrum analyzer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> MinimumFrequency<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>MinimumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>MinimumFrequencyProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The number of bars to show on the sprectrum analyzer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;A bar's width can be a minimum of 1 pixel. If the BarSpacing and BarCount property result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// in the bars being wider than the chart itself, the BarCount will automatically scale down.&lt;/remarks&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> BarCount<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarCountProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarCountProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The brush used to paint the bars on the spectrum analyzer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Brush BarBrush<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>Brush<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarBrushProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarBrushProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The brush used to paint the peaks on the spectrum analyzer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Brush PeakBrush<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>Brush<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>PeakBrushProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>PeakBrushProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The delay factor for the peaks falling. This is relative to the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// refresh rate of the chart.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> PeakFallDelay<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>PeakFallDelayProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>PeakFallDelayProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The spacing, in pixels, between the bars.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> BarSpacing<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarSpacingProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarSpacingProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, the bar height will be displayed linearly with the intensity value.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// Otherwise, the bars will be scaled with a square root function.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> BarHeightScaling BarHeightScaling<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>BarHeightScaling<span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>BarHeightScalingProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>BarHeightScalingProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, this will display the frequency scale (X-axis of the spectrum analyzer)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// in a linear scale. Otherwise, the scale will be logrithmic.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> FrequencyScaleIsLinear<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>FrequencyScaleIsLinearProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>FrequencyScaleIsLinearProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// If true, each bar's peak value will be averaged with the previous</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// bar's peak. This creates a smoothing effect on the bars.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Common&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AveragePeaks<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>AveragePeaksProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>AveragePeaksProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">int</span> StreamHandle<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>StreamHandleProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetValue<span style="color: #008000;">&#40;</span>StreamHandleProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>StreamHandle <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BASS_CHANNELINFO info <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> BASS_CHANNELINFO<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bass<span style="color: #008000;">.</span><span style="color: #0000FF;">BASS_ChannelGetInfo</span><span style="color: #008000;">&#40;</span>StreamHandle, info<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sampleFrequency <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">freq</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sampleFrequency <span style="color: #008000;">=</span> <span style="color: #FF0000;">44100</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarMappingChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Dependency Property Validation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> CoerceMaximumFrequency<span style="color: #008000;">&#40;</span>DependencyObject d, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value <span style="color: #008000;">&lt;</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">MinimumFrequency</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">MinimumFrequency</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> CoerceMinimumFrequency<span style="color: #008000;">&#40;</span>DependencyObject d, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> returnValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpectrumAnalyzer spectrumAnalyzer <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>d<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>returnValue <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> returnValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValue</span><span style="color: #008000;">&#40;</span>MaximumFrequencyProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> returnValue<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> CoerceBarCount<span style="color: #008000;">&#40;</span>DependencyObject d, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> returnValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnValue <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>returnValue, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> returnValue<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> CoercePeakFallDelay<span style="color: #008000;">&#40;</span>DependencyObject d, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> returnValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnValue <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>returnValue, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> returnValue<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">object</span> CoerceBarSpacing<span style="color: #008000;">&#40;</span>DependencyObject d, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> returnValue <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returnValue <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>returnValue, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> returnValue<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Constructors</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> SpectrumAnalyzer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// MaximumFrequency</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FrameworkPropertyMetadata maximumFrequencyMetadata <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maximumFrequencyMetadata<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValueCallback</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceMaximumFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MaximumFrequencyProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MaximumFrequency&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, maximumFrequencyMetadata<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// MinimumFrequency</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FrameworkPropertyMetadata minimumFrequencyMetadata <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minimumFrequencyMetadata<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValueCallback</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceMinimumFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MinimumFrequencyProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MinimumFrequency&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, minimumFrequencyMetadata<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// BarCount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FrameworkPropertyMetadata barCountMetadata <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">24</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barCountMetadata<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValueCallback</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceBarCount</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarCountProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarCount&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, barCountMetadata<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// BarSpacing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FrameworkPropertyMetadata barSpacingMetadata <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">5.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barSpacingMetadata<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValueCallback</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceBarSpacing</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarSpacingProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BarSpacing&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, barSpacingMetadata<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// PeakFallDelay</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FrameworkPropertyMetadata peakFallDelayMetadata <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakFallDelayMetadata<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceValueCallback</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CoerceValueCallback<span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">CoercePeakFallDelay</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PeakFallDelayProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PeakFallDelay&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span>, peakFallDelayMetadata<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> SpectrumAnalyzer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PeakBrush <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">GreenYellow</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarBrush <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> LinearGradientBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">ForestGreen</span>, Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">DarkGreen</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Point<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Point<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DispatcherTimer<span style="color: #008000;">&#40;</span>DispatcherPriority<span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationIdle</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Interval</span> <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">25</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Tick</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> EventHandler<span style="color: #008000;">&#40;</span>animationTimer_Tick<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyPropertyDescriptor backgroundDescriptor <span style="color: #008000;">=</span> DependencyPropertyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">FromProperty</span><span style="color: #008000;">&#40;</span>BackgroundProperty, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backgroundDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, AppearanceChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyPropertyDescriptor barBrushDescriptor <span style="color: #008000;">=</span> DependencyPropertyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">FromProperty</span><span style="color: #008000;">&#40;</span>BarBrushProperty, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barBrushDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, AppearanceChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyPropertyDescriptor maxFrequencyDescriptor <span style="color: #008000;">=</span> DependencyPropertyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">FromProperty</span><span style="color: #008000;">&#40;</span>MaximumFrequencyProperty, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxFrequencyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, BarMappingChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyPropertyDescriptor minFrequencyDescriptor <span style="color: #008000;">=</span> DependencyPropertyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">FromProperty</span><span style="color: #008000;">&#40;</span>MinimumFrequencyProperty, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxFrequencyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, BarMappingChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyPropertyDescriptor barCountDescriptor <span style="color: #008000;">=</span> DependencyPropertyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">FromProperty</span><span style="color: #008000;">&#40;</span>BarCountProperty, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>SpectrumAnalyzer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxFrequencyDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValueChanged</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, BarMappingChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarMappingChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>DesignerProperties<span style="color: #008000;">.</span><span style="color: #0000FF;">GetIsInDesignMode</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bassEngine <span style="color: #008000;">=</span> BassEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Instance</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">Bind</span><span style="color: #008000;">&#40;</span>bassEngine, <span style="color: #666666;">&quot;ActiveStreamHandle&quot;</span>, <span style="color: #0600FF; font-weight: bold;">this</span>, StreamHandleProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; animationTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">void</span> animationTimer_Tick<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Event Overrides</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRender<span style="color: #008000;">&#40;</span>DrawingContext dc<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnRender</span><span style="color: #008000;">&#40;</span>dc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anaylzerBuffer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RenderTargetBitmap<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span>, <span style="color: #FF0000;">96</span>, <span style="color: #FF0000;">96</span>, PixelFormats<span style="color: #008000;">.</span><span style="color: #0000FF;">Pbgra32</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>SpectrumImage <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SpectrumImage<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span> <span style="color: #008000;">=</span> anaylzerBuffer<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRenderSizeChanged<span style="color: #008000;">&#40;</span>SizeChangedInfo sizeInfo<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnRenderSizeChanged</span><span style="color: #008000;">&#40;</span>sizeInfo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BarMappingChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Private Utility Methods</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bassEngine <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> drawingVisual <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> anaylzerBuffer <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>bassEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPaused</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>StreamHandle <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>GetFFTBuffer<span style="color: #008000;">&#40;</span>StreamHandle, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>maxFFT<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Clear Canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anaylzerBuffer<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>DrawingContext drawingContext <span style="color: #008000;">=</span> drawingVisual<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderOpen</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Draw background if applicable. &nbsp; &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Background <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawingContext<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawRectangle</span><span style="color: #008000;">&#40;</span>Background, <span style="color: #0600FF; font-weight: bold;">null</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rect<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span>, RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Draw Spectrum Lines</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenderSpectrumLines<span style="color: #008000;">&#40;</span>drawingContext<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anaylzerBuffer<span style="color: #008000;">.</span><span style="color: #0000FF;">Render</span><span style="color: #008000;">&#40;</span>drawingVisual<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> GetFFTBuffer<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> handle, <span style="color: #6666cc; font-weight: bold;">int</span> length<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Un4seen<span style="color: #008000;">.</span><span style="color: #0000FF;">Bass</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Bass</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BASS_ChannelGetData</span><span style="color: #008000;">&#40;</span>handle, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelData</span>, length<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderSpectrumLines<span style="color: #008000;">&#40;</span>DrawingContext dc<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> fftBucketHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> lastPeakHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> peakYPos <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> height <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RenderSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> barIndex <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> peakDotHeight <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">/</span> 2<span style="color: #008000;">.</span>0f, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> barHeightScale <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> peakDotHeight<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> minDBValue <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">90</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> maxDBValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">double</span> dbScale <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>maxDBValue <span style="color: #008000;">-</span> minDBValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> minimumFrequencyIndex<span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> maximumFrequencyIndex<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If we're paused, keep drawing, but set the current height to 0 so the peaks fall.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bassEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">IsPaused</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// Draw the maximum value for the bar's band</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>BarHeightScaling<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BandedSpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">BarHeightScaling</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Decibel</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> dbValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span> <span style="color: #008000;">*</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log10</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>channelData<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>dbValue <span style="color: #008000;">-</span> minDBValue<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> dbScale<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BandedSpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">BarHeightScaling</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Linear</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>channelData<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">*</span> scaleFactorLinear<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> BandedSpectrumAnalyzer<span style="color: #008000;">.</span><span style="color: #0000FF;">BarHeightScaling</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fftBucketHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelData</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> scaleFactorSqr<span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> barHeightScale<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&lt;</span> fftBucketHeight<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> fftBucketHeight<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&lt;</span> 0f<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If this is the last FFT bucket in the bar's group, draw the bar.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> currentIndexMax <span style="color: #008000;">=</span> FrequencyScaleIsLinear <span style="color: #008000;">?</span> barIndexMax<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">:</span> barLogScaleIndexMax<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">==</span> currentIndexMax<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Peaks can't surpass the height of the control.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>barHeight <span style="color: #008000;">&gt;</span> height<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> height<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>AveragePeaks <span style="color: #008000;">&amp;&amp;</span> barIndex <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>lastPeakHeight <span style="color: #008000;">+</span> barHeight<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peakYPos <span style="color: #008000;">=</span> barHeight<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>channelPeakData<span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">&lt;</span> peakYPos<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelPeakData</span><span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>peakYPos<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelPeakData</span><span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>peakYPos <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>PeakFallDelay <span style="color: #008000;">*</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelPeakData</span><span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>PeakFallDelay <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> xCoord <span style="color: #008000;">=</span> BarSpacing <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">*</span> barIndex<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>BarSpacing <span style="color: #008000;">*</span> barIndex<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Draw the bars</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>BarBrush <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dc<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawRectangle</span><span style="color: #008000;">&#40;</span>BarBrush, <span style="color: #0600FF; font-weight: bold;">null</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rect<span style="color: #008000;">&#40;</span>xCoord, <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> barHeight, barWidth, barHeight<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Draw the peaks</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>PeakBrush <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dc<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawRectangle</span><span style="color: #008000;">&#40;</span>PeakBrush, <span style="color: #0600FF; font-weight: bold;">null</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Rect<span style="color: #008000;">&#40;</span>xCoord, <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">channelPeakData</span><span style="color: #008000;">&#91;</span>barIndex<span style="color: #008000;">&#93;</span>, barWidth, peakDotHeight<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lastPeakHeight <span style="color: #008000;">=</span> barHeight<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barHeight <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barIndex<span style="color: #008000;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Dependency Property Changed Handlers</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AppearanceChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateSpectrum<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> BarMappingChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barWidth <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> <span style="color: #008000;">&#40;</span>BarSpacing <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>BarCount <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>BarCount<span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maximumFrequencyIndex <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>Utils<span style="color: #008000;">.</span><span style="color: #0000FF;">FFTFrequency2Index</span><span style="color: #008000;">&#40;</span>MaximumFrequency, maxFFTData, sampleFrequency<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">2047</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minimumFrequencyIndex <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>Utils<span style="color: #008000;">.</span><span style="color: #0000FF;">FFTFrequency2Index</span><span style="color: #008000;">&#40;</span>MinimumFrequency, maxFFTData, sampleFrequency<span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">2047</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bandWidth <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex <span style="color: #008000;">-</span> minimumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span>, <span style="color: #FF0000;">1.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> actualBarCount <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>RenderSize<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> BarSpacing<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span>barWidth <span style="color: #008000;">+</span> BarSpacing<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channelPeakData <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#91;</span>actualBarCount<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> indexCount <span style="color: #008000;">=</span> maximumFrequencyIndex <span style="color: #008000;">-</span> minimumFrequencyIndex<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> linearIndexBucketSize <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Round</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>indexCount <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>actualBarCount, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> maxIndexList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> maxLogScaleIndexList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">double</span> maxLog <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>actualBarCount, actualBarCount<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> actualBarCount <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>minimumFrequencyIndex <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> linearIndexBucketSize<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> logIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>maxLog <span style="color: #008000;">-</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>actualBarCount <span style="color: #008000;">-</span> i, actualBarCount<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> indexCount<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> minimumFrequencyIndex<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>logIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>maximumFrequencyIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barIndexMax <span style="color: #008000;">=</span> maxIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; barLogScaleIndexMax <span style="color: #008000;">=</span> maxLogScaleIndexList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> BarHeightScaling<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Decibel,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Sqrt,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Linear<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The UpdateSpectrum() method is handling the writing of our bar drawing to the buffer. Using a DrawingVisual and DrawingContext directly gives me great performance. I currently have the timer on this Spectrum Analyzer to draw every 25 ms (which translates to about 40 FPS). Even at this speed, I find the application barely registering 1% CPU, and that&#8217;s in the confines of a virtual machine. The actual method I&#8217;m using to draw FFT data is inside of RenderSpectrumLines(). You&#8217;ll note that we take the peak value in the frequency range of a bar and display that. This is all pretty standard fare for this sort of spectrum analyzer. I encourage you to read up on Fast Fourier Transforms and Audio Processing if this interests you.</p>
<div id="attachment_382" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2011/02/SpectrumAnalyzerWhite.png" target="_blank"><img src="http://inchoatethoughts.com/wp-content/uploads/2011/02/SpectrumAnalyzerWhite-300x217.png" alt="Spectrum Analyzer Control With A Light Theme" title="Spectrum Analyzer Control With A Light Theme" width="300" height="217" class="size-medium wp-image-382" /></a><p class="wp-caption-text">Spectrum Analyzer Control With A Light Theme</p></div>
<p>That&#8217;s pretty much it! As you can see, I dropped the control in a Window, added some basic playback controls, tag reading, and fancy WPF reflection to give it a nice look. I encourage you to download the <a href="http://inchoatethoughts.com/uploads/WPFSpectrumAnalyzer.zip" target="_blank">source code</a> if you&#8217;re interested in including something like this in your own WPF application.  If you have questions, see room for improvement, or have useful information I left out, please leave me a comment!</p>
<p><strong><a href="http://wpfsvl.codeplex.com/" target="_blank">Download the Spectrum Analyzer and Source Code As Part of the WPF Sound Visualization Library</a></strong><br />
<strong><a href="http://inchoatethoughts.com/uploads/OldWPFSpectrumAnalyzer.zip" target="_blank">Download Source Code For This Post (Deprecated!)</a></strong></p>
<p><strong>Update 2/6/2011:</strong></p>
<ul>
<li>Cleaned up some unused references. (Had System.Drawing in there, oops!)</li>
<li>Added XML comments to dependency properties on SpectrumAnalyzer UserControl</li>
<li>Revised theme selection layout</li>
<li>Exposed BarSpacing Property (was accidentally made private)</li>
<li>Added AveragePeaks Dependency Property</li>
<li>Gradiated backgrounds to demonstrate true WPF transparency support</li>
<li>Added option to make the X Axis (Frequency) scale logrithmicly</li>
<li>Added another height scaling configuration, decibel. &#8220;BarHeightIsLinear&#8221; property replaced with &#8220;BarHeightScaling&#8221;</li>
<li>Optimized bar bucket check.</li>
<li>Moved all of the Bass logic into an INotifyPropertyChanged class so binding is possible</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/a-wpf-spectrum-analyzer-for-audio-visualization/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Updated XBMC and Boxee Launchers &#8211; Now With Installers!</title>
		<link>http://inchoatethoughts.com/updated-xbmc-and-boxee-launchers-now-with-installers</link>
		<comments>http://inchoatethoughts.com/updated-xbmc-and-boxee-launchers-now-with-installers#comments</comments>
		<pubDate>Sat, 23 Oct 2010 22:54:35 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Boxee]]></category>
		<category><![CDATA[Green Button]]></category>
		<category><![CDATA[Media Center]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[XBMC]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=339</guid>
		<description><![CDATA[My little launchers aimed at making XBMC and Boxee work with the Windows Media Center have been updated. I think the largest thing to note is that they now have an installer thanks to a comment left by user Joshka. I&#8217;ve also made some tweaks so that the media centers *really* get brought to the [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_340" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/10/XBMCBoxee.png"><img class="size-full wp-image-340" title="XBMC / Boxee Launchers Updated" src="http://inchoatethoughts.com/wp-content/uploads/2010/10/XBMCBoxee.png" alt="XBMC / Boxee Launchers Updated" width="300" height="250" /></a><p class="wp-caption-text">XBMC / Boxee Launchers Updated</p></div>
<p style="text-align: center;">
<p>My little launchers aimed at making XBMC and Boxee work with the Windows Media Center have been updated. I think the largest thing to note is that they now have an installer thanks to a comment left by user Joshka. I&#8217;ve also made some tweaks so that the media centers *really* get brought to the foreground should they be moved back for some reason. Finally, users now have the abilities to feed in any parameters they want to the launchers. I know a few of you like to use custom parameters above and beyond the standard portable mode flags. For those of you just wanting to do portable mode, that is taken care of in the installer!</p>
<p><a title="Get XBMC Launcher" href="http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote" target="_self">Get XBMC Launcher</a></p>
<p><a title="Get Boxee Launcher" href="http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote" target="_self">Get Boxee Launcher</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/updated-xbmc-and-boxee-launchers-now-with-installers/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Launching Boxee with a Windows Media Center Remote</title>
		<link>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote</link>
		<comments>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote#comments</comments>
		<pubDate>Fri, 04 Jun 2010 04:28:49 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Boxee]]></category>
		<category><![CDATA[Green Button]]></category>
		<category><![CDATA[Media Center]]></category>
		<category><![CDATA[Remote]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=322</guid>
		<description><![CDATA[Updated 10/23/2010: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy! I was recently notified that Boxee might [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_324" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/06/Boxee.png"><img class="size-medium wp-image-324" title="Boxee" src="http://inchoatethoughts.com/wp-content/uploads/2010/06/Boxee-300x187.png" alt="Boxee" width="300" height="187" /></a><p class="wp-caption-text">Boxee</p></div>
<p><strong>Updated 10/23/2010</strong>: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy!</p>
<p>I was recently notified that Boxee might benefit from the same hack I used to get XBMC working with my Windows Media Center remote (see the <a href="http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote">post</a> before this one). The problem was the same. While you can use a Windows Media Center remote and IR receiver (or a universal remote emulating one) to control Boxee, the green button will continue to launch Windows Media Center. I was asked to modify the little launcher I had written for launching XBMC to launch Boxee instead. About 10 seconds of coding (and another 5 minutes of testing) later, I had what appears to be a working solution.</p>
<p><a title="Download BoxeeLauncher Installer" href="http://inchoatethoughts.com/files/InstallBoxeeLauncher.exe" target="_blank">Download BoxeeLauncher Installer</a><br />
<a title="Download BoxeeLauncher Manual Install" href="http://inchoatethoughts.com/files/BoxeeLauncher_Manual.zip" target="_blank">Download BoxeeLauncher Manual Install</a></p>
<p>Source code, project files, and install scripts can be found at <a title="BoxeeLauncher Subversion Repository" href="http://inchoatethoughts.com/boxeelauncher/" target="_blank">http://inchoatethoughts.com/boxeelauncher/</a> (subversion repository)</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/launching-boxee-with-a-windows-media-center-remote/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Launching XBMC with a Windows Media Center Remote</title>
		<link>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote</link>
		<comments>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote#comments</comments>
		<pubDate>Sun, 14 Feb 2010 04:29:57 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Green Button]]></category>
		<category><![CDATA[Media Center]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[XBMC]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=306</guid>
		<description><![CDATA[Updated 10/23/2010: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy! I recently took up the task of [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_307" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/02/xbmc.png"><img class="size-medium wp-image-307" title="XBMC" src="http://inchoatethoughts.com/wp-content/uploads/2010/02/xbmc-300x176.png" alt="XBMC" width="300" height="176" /></a><p class="wp-caption-text">XBMC</p></div>
<p><strong>Updated 10/23/2010</strong>: Based on some comments, I&#8217;ve released a new version with an installer and file for defining custom parameters. Big thanks to Joshka for showing me a neat registry trick that allowed me to create the installer. I&#8217;ve also moved the source to a subversion repository. Enjoy!</p>
<p style="text-align: left;">I recently took up the task of switching my media center software from Windows 7 Media Center to the Windows version of XBMC. I found XBMC easier to get working with obscure encodings of video files (it uses mplayer instead of the normal codec engine). But, my reasons for switching are not the point of this post. The point here is that switching to XBMC from Windows Media Center has a few challenges. One such challenge is getting the Windows Media Center remote to work in a nice way. Luckily, some <a href="http://xbmcmce.sourceforge.net/">excellent work</a> has been done on that front. People have already provided premade media center remote configurations for XBMC. However, the &#8220;start&#8221; button on the media center remote <a href="http://forum.xbmc.org/showthread.php?t=65088">still had the nasty habit of launching the Windows 7 Media Center app instead of launching XBMC</a>.</p>
<p style="text-align: left;">I looked around the ol&#8217; Internet for a solution to this problem. Turns out, the behavior of that &#8220;Start&#8221; or &#8220;Green&#8221; button on the media center remote is to cause a special key combination to be pressed. This key combination is bound to launching &#8220;C:\Windows\ehome\ehshell.exe.&#8221; The quickest workaround to the problem is to change ehshell.exe to something that launches XBMC. I then saw some people had written some batch files that launched XBMC. They then used a batch-to-exe converter to make it an executable and replaced ehshell.exe. That was great, but it still had a weakness. If, for some reason, XBMC was taken out of the foreground, it wouldn&#8217;t come back. Bummer. So I fixed it!</p>
<p style="text-align: left;">I wrote a little application to launch XBMC. It does a few things. First, it will check if XBMC is already running. If it is, it will bring it to the foreground for you. If it isn&#8217;t running, it will launch it. It will first try using the install location in the registry to find where to launch XBMC from. If it can&#8217;t find that, it will try the default location of the XBMC.exe file (both 32-bit and 64-bit versions).</p>
<p style="text-align: left;"><a title="XBMC Launcher Installer" href="http://inchoatethoughts.com/files/InstallXBMCLauncher.exe" target="_blank">Download The Installer</a></p>
<p style="text-align: left;"><a title="XBMC Launcher Manual Install" href="http://inchoatethoughts.com/files/XBMCLauncher_Manual.zip" target="_blank">Manual Install Files and Instructions</a></p>
<p>Finally, here is the (very simple) source code:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Diagnostics</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Win32</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> XbmcLauncher<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SetForegroundWindow<span style="color: #008000;">&#40;</span>IntPtr hWnd<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ShowWindow<span style="color: #008000;">&#40;</span>IntPtr hWnd, <span style="color: #6666cc; font-weight: bold;">int</span> cmdShow<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> SW_SHOWMAXIMIZED <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// The main entry point for the application.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Attempt to bring an existing XBMC to the foreground.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If none exists, open XBMC.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenXbmc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> processes <span style="color: #008000;">=</span> Process<span style="color: #008000;">.</span><span style="color: #0000FF;">GetProcessesByName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>processes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If XBMC is currently running, bring it to the foreground</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr hWnd <span style="color: #008000;">=</span> processes<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MainWindowHandle</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowWindow<span style="color: #008000;">&#40;</span>hWnd, SW_SHOWMAXIMIZED<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow<span style="color: #008000;">&#40;</span>hWnd<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> OpenXbmc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> xbmcPath <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Attempt to find the XBMC executable location via the registry</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RegistryKey key <span style="color: #008000;">=</span> Registry<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentUser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OpenSubKey</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;Software\XBMC&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>key <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// If the path is in the registry use it to open XBMC</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xbmcPath <span style="color: #008000;">=</span> key<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LaunchXbmcProcess<span style="color: #008000;">&#40;</span>xbmcPath <span style="color: #008000;">+</span> <span style="color: #666666;">@&quot;\XBMC.exe&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// Otherwise, we'll try to use the default locations</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> x86Path <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Program Files\XBMC\XBMC.exe&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> x64Path <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Program Files (x86)\XBMC\XBMC.exe&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LaunchXbmcProcess<span style="color: #008000;">&#40;</span>x86Path<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LaunchXbmcProcess<span style="color: #008000;">&#40;</span>x64Path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> LaunchXbmcProcess<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> path<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>path <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> args <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process proc <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Process<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMCLaunchArgs.txt&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>StreamReader argStream <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenText</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;XBMCLaunchArgs.txt&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args <span style="color: #008000;">=</span> argStream<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; argStream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc<span style="color: #008000;">.</span><span style="color: #0000FF;">StartInfo</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ProcessStartInfo<span style="color: #008000;">&#40;</span>path, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proc<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BringProcessToForeground<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p style="text-align: left;">Get the full source, project files, and install scripts at <a title="XBMC Launcher Manual Install" href="http://inchoatethoughts.com/xbmclauncher/ " target="_blank">http://inchoatethoughts.com/xbmclauncher/</a> (subversion)</p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/launching-xbmc-with-a-windows-media-center-remote/feed</wfw:commentRss>
		<slash:comments>93</slash:comments>
		</item>
		<item>
		<title>foo_g15lcd 0.3c</title>
		<link>http://inchoatethoughts.com/foo_g15lcd-0-3c</link>
		<comments>http://inchoatethoughts.com/foo_g15lcd-0-3c#comments</comments>
		<pubDate>Wed, 27 Jan 2010 00:29:20 +0000</pubDate>
		<dc:creator>Jacob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Foobar2000]]></category>
		<category><![CDATA[foo_g15lcd]]></category>
		<category><![CDATA[Logitech]]></category>

		<guid isPermaLink="false">http://inchoatethoughts.com/?p=296</guid>
		<description><![CDATA[This is just a quick little update to let everyone know I&#8217;ve recompiled the foo_g15lcd component against the latest release version of Foobar 1.0. No new features, but everything still seems to be in excellent working order! Grab it here: Download foo_g15lcd 0.3c]]></description>
			<content:encoded><![CDATA[<div id="attachment_297" class="wp-caption aligncenter" style="width: 310px"><a href="http://inchoatethoughts.com/wp-content/uploads/2010/01/foog1503c.png"><img class="size-medium wp-image-297" title="foo_g15lcd 0.3c" src="http://inchoatethoughts.com/wp-content/uploads/2010/01/foog1503c-300x135.png" alt="" width="300" height="135" /></a><p class="wp-caption-text">foo_g15lcd 0.3c</p></div>
<p style="text-align: center;">
<p>This is just a quick little update to let everyone know I&#8217;ve recompiled the foo_g15lcd component against the latest release version of Foobar 1.0. No new features, but everything still seems to be in excellent working order!</p>
<p>Grab it here: <a href="http://www.inchoatethoughts.com/foo_g15lcd/foo_g15lcd_0_3_c.zip">Download foo_g15lcd 0.3c</a></p>
]]></content:encoded>
			<wfw:commentRss>http://inchoatethoughts.com/foo_g15lcd-0-3c/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

