<?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>bitplane.net &#187; Gaz Davidson</title>
	<atom:link href="http://bitplane.net/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://bitplane.net</link>
	<description>Rants, ramblings, free software</description>
	<lastBuildDate>Thu, 09 Feb 2012 02:37:56 +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>Bubbler: Monitoring homebrew CO2 production using arecord and Python</title>
		<link>http://bitplane.net/2012/02/airlock-mic-project/</link>
		<comments>http://bitplane.net/2012/02/airlock-mic-project/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 21:14:48 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[home-brewing]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sensors]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=830</guid>
		<description><![CDATA[A couple of weeks back I was thinking about monitors and sensors and had a crazy idea: it ought to be possible to gather stats on how well my plonk is fermenting by attaching a mic to the airlock and counting the bubbles. So in a moment of enthusiasm I ordered a cheap lapel microphone [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks back I was thinking about monitors and sensors and had a crazy idea: it ought to be possible to gather stats on how well my plonk is fermenting by attaching a mic to the airlock and counting the bubbles. So in a moment of enthusiasm I ordered a cheap lapel microphone from eBay and forgot all about it&#8230; until Saturday morning when it finally arrived in the post.</p>
<p>Time for some fun!</p>
<p><span id="more-830"></span></p>
<p>The first thing I did was break the plastic housing off the mic and exposed the sensor, I snipped off the headphone socket and taped up the rest. It&#8217;s not the prettiest bit of electrical tape you&#8217;re likely to see, but it does the job:</p>
<p><a href="http://bitplane.net/wp-content/uploads/2012/02/butchered-mic.jpg"><img class="size-medium wp-image-832 alignnone" title="Butchering the mic" src="http://bitplane.net/wp-content/uploads/2012/02/butchered-mic-210x300.jpg" alt="" width="210" height="300" /></a> <a href="http://bitplane.net/wp-content/uploads/2012/02/butchered-mic-1.jpg"><img class="size-medium wp-image-831 alignnone" title="Butchered mic front" src="http://bitplane.net/wp-content/uploads/2012/02/butchered-mic-1-223x300.jpg" alt="" width="223" height="300" /></a></p>
<p>I then taped the mic to the airlock roughly at the area where the bubbles will be, then taped the whole thing up to make it a bit more water-resistant.</p>
<p><a href="http://bitplane.net/wp-content/uploads/2012/02/airlock.jpg"><img class="alignnone size-medium wp-image-833" title="airlock" src="http://bitplane.net/wp-content/uploads/2012/02/airlock-160x300.jpg" alt="" width="160" height="300" /></a> <a href="http://bitplane.net/wp-content/uploads/2012/02/mic-attached.jpg"><img class="size-medium wp-image-834 alignnone" title="Mic attached" src="http://bitplane.net/wp-content/uploads/2012/02/mic-attached-300x264.jpg" alt="" width="300" height="264" /></a></p>
<p>Okay, now onto the fun bit: writing the software <img src='http://bitplane.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The easiest way to get sound from the mic port is to use <abbr title="Advanced Linux Sound Architecture">ALSA</abbr>&#8216;s arecord, which comes as part of <a href="http://www.alsa-project.org/main/index.php/Download">alsa-utils</a> and should already be installed on your distro. Run amixer from the command line to find the correct input and unmute it if required, but in most cases just running arecord will work. I set my volume levels to be 100% (unamplified) as I want to be the only person messing with the data.</p>
<p>I&#8217;m after a raw stream of data without any of that WAV header nonsense, so throwing a stream of raw longs to stdout looks a little like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">gaz@beast:~$ arecord --format=S32_LE --file-type=raw</pre></div></div>

<p>The next task is detecting the bubbles in this raw data. The mic is touching the airlock so the bubbles are very loud and high pitched, so plugging in a high pass filter might help get rid of any background noise. I found that using Audacity&#8217;s high pass filter managed to keep the bubble track intact while filtering out most of the the sound of a vacuum cleaner, which is pretty impressive. I didn&#8217;t write my own high pass filter as it seems to work okay without one, maybe I&#8217;ll make an <abbr title="Fast Fourier Transform">FFT</abbr>-based one in the future.</p>
<p>For the moment though, I simply defined a bubble-part as a volume reading that is two standard deviations away from the mean, where the mean is taken by summing the distance of each sample from the base line; waves always add up to 0, so we need an absolute measurement from the base line or the average will always be 0. If this bubble part is more than t milliseconds from the last one, then we have a new bubble.</p>
<p>My limited testing shows that the bubble count appears to be roughly right even when I&#8217;m playing music in the background, but it will probably need some tweaks before it works in all cases. So far it&#8217;s only been tested with my 25 litre plastic wine fermenter, so I have no idea how it will perform on demijohns. I can think of a number of things that are wrong with the algorithm too.</p>
<p>For a start it&#8217;s adaptive, so if you simply unplug the cable then the odd bubble will be detected. A minimum bubble length may help here. Secondly, the averages are taken from the last listening period so it&#8217;s all dependent on the length of this window, moving averages might be better, but would be more processor intensive (as if Python wasn&#8217;t processor intensive enough) and I have no idea what that does statistically, but I imagine it&#8217;s not good from a purist perspective. Finally, it&#8217;s using average volume of each |sample value| but it actually uses peak levels to detect bubbles, so I guess that it ought to be using the maximum |sample value| over N samples where N is equivalent to some minimum frequency.</p>
<p>Ignoring all that it appears to work okay. Here&#8217;s a graph that shows it in action along with my <a href="http://bitplane.net/2012/01/temper1-ubuntu/">thermometer</a>, the dip is caused by me dismantling it while taking the photos above.</p>
<p><a href="http://bitplane.net/wp-content/uploads/2012/02/BPM-chart.png"><img class="wp-image-841 alignnone" title="Graphing the data" src="http://bitplane.net/wp-content/uploads/2012/02/BPM-chart.png" alt="" width="494" height="292" /></a></p>
<p>You can download or fork the the code over <a href="https://github.com/bitplane/bubbler">github</a>.</p>
<p>Happy brewing!</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2012/02/airlock-mic-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TEMPer1 temperature sensor in Linux</title>
		<link>http://bitplane.net/2012/01/temper1-ubuntu/</link>
		<comments>http://bitplane.net/2012/01/temper1-ubuntu/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 23:36:12 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sensors]]></category>
		<category><![CDATA[temper1]]></category>
		<category><![CDATA[thermometer]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=825</guid>
		<description><![CDATA[Yey! Just got my PCSensor TEMPer1 USB thermometer logging in Linux. It automatically detects and does expose USB HID profiles, but there&#8217;s no way to access the data by holding down the CAPS key like it says in the docs. Thankfully, a search for the device ID (0c45:7401 Microdia) finds ruby bindings for Temper.c by Michitaka Ohno, [...]]]></description>
			<content:encoded><![CDATA[<p>Yey! Just got my <a href="http://pcsensor.com/index.php?_a=viewProd&amp;productId=7">PCSensor TEMPer1 USB thermometer</a> logging in Linux. It automatically detects and does expose USB HID profiles, but there&#8217;s no way to access the data by holding down the CAPS key like it says in the docs.</p>
<p>Thankfully, a search for the device ID (0c45:7401 Microdia) finds ruby bindings for Temper.c by <a href="https://github.com/elpeo">Michitaka Ohno</a>, which conveniently includes the reverse-engineered USB protocol. So I&#8217;ve <a href="https://github.com/bitplane/temper">forked this on GitHub</a>, removed the Ruby bits, edited the unit test wrapped it up in a little script that logs the time and temperature to a CSV file. It currently only supports one device, which will change if I ever get another one of these devices (spoiler: I probably will)</p>
<p><span id="more-825"></span></p>
<p>To start logging your TEMPer1&#8242;s data in Ubuntu just</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;"># install dependencies</span>
 $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git</span> build-essential libusb-0.1.4 libusb-0.1.4-dev
 <span style="color: #666666; font-style: italic;"># clone the logger</span>
 $ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>bitplane<span style="color: #000000; font-weight: bold;">/</span>temper.git
 <span style="color: #666666; font-style: italic;"># build it</span>
 $ <span style="color: #7a0874; font-weight: bold;">cd</span> temper
 $ <span style="color: #c20cb9; font-weight: bold;">make</span> clean
 $ <span style="color: #c20cb9; font-weight: bold;">make</span>
 <span style="color: #666666; font-style: italic;"># start logging!</span>
 $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>log.sh <span style="color: #000000; font-weight: bold;">&amp;</span>gt; temperature.log</pre></div></div>

<p>Now I&#8217;m just waiting for my USB clip-on-mic to arrive. Once it does I can log the bubbles from the airlock on my beverages along with the temperature, and make some pretty graphs.</p>
<p>Watch this space!</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2012/01/temper1-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu printing and scanning</title>
		<link>http://bitplane.net/2012/01/hp-officejet-4500-ubuntu/</link>
		<comments>http://bitplane.net/2012/01/hp-officejet-4500-ubuntu/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 17:18:56 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[HP]]></category>
		<category><![CDATA[printer]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=812</guid>
		<description><![CDATA[I haven&#8217;t owned a printer since I had an Amiga all those years ago, but since I&#8217;ve started my homebrew mission I&#8217;ve decided I need something to print some labels. Kath got me a HP OfficeJet 4500 G510g printer/scanner/copier for my birthday, and I have to say it works wonderfully. My last experience with a printer [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t owned a printer since I had an Amiga all those years ago, but since I&#8217;ve started my homebrew mission I&#8217;ve decided I need something to print some labels. Kath got me a HP OfficeJet 4500 G510g printer/scanner/copier for my birthday, and I have to say it works wonderfully.</p>
<p><span id="more-812"></span></p>
<p>My last experience with a printer in Ubuntu was when I attempted to use an old Lexmark Z-something, there were no Linux drivers and after much struggling I had to reboot into Windows to use it. The Windows drivers were close to a hundred megabytes, sluggish, always running and came complete with an intrusive systray app to further sap system resources. The app had a non-standard and ugly UI plus annoying American voice that begged me to &#8220;please insert paper in the auto sheet-feeder&#8221; each time I tried to print something. I remember Canon doing a similar thing with their Windows software too which is one reason why I&#8217;ve avoided printers for all these years. That sort of blatant disregard for system resources and desktop space makes the overhead of attaching a printer weigh in heavier than the reward it offers.</p>
<p>I don&#8217;t know whether it&#8217;s HP&#8217;s, Canonical&#8217;s or Debian&#8217;s idea but the experience with my OfficeJet 4500 in Ubuntu has been great. Rather than having to download drivers I just plugged it in. I installed gLabels from the Software Center and printed out some labels within minutes. Pressing meta and typing &#8220;print&#8221; takes me to Gnome&#8217;s Printing app which lists my printer and its fax machine counterpart (remember those?!), and I can right click and set quality settings and so on in a standard UI:</p>
<p><a href="http://bitplane.net/2012/01/hp-officejet-4500-ubuntu/printer/" rel="attachment wp-att-813"><img class="aligncenter size-medium wp-image-813" title="printer" src="http://bitplane.net/wp-content/uploads/2012/01/printer-300x206.png" alt="" width="300" height="206" /></a></p>
<p>Keying &#8220;scan&#8221; into Unity&#8217;s search bar takes me to Canonical&#8217;s &#8220;Simple Scan&#8221; which really is as easy as π, it just scans. Before I could scan through Gimp I had to install XSane, which a bit of a mess. It opens four windows and somehow transfers to Gimp as JPEG by default, leaving 16&#215;16 JPEG compression artefacts in my scanned images. These look bad even if I choose 100% quality in the menu, so it looks like the quality settings are ignored:</p>
<p><a href="http://bitplane.net/wp-content/uploads/2012/01/Jaggies.png"><img class="aligncenter size-medium wp-image-814" title="Jaggies" src="http://bitplane.net/wp-content/uploads/2012/01/Jaggies-300x208.png" alt="" width="300" height="208" /></a></p>
<p>edit: A bit of investigation showed that this is due to Sane&#8217;s XP driver using 10% JPEG compression by default. This can be disabled via the <em>Window -&gt; Show advanced options</em> dialog.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2012/01/hp-officejet-4500-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Irrlicht website update</title>
		<link>http://bitplane.net/2012/01/irrlicht-website-update/</link>
		<comments>http://bitplane.net/2012/01/irrlicht-website-update/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 07:39:39 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Irrlicht]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=804</guid>
		<description><![CDATA[The WordPress version of the Irrlicht website is now live, which means we can edit pages and post news articles using an online editor, users can post comments and we can even appoint community editors to post stuff without giving them rights to the filesystem. Expect lots more activity there in the future]]></description>
			<content:encoded><![CDATA[<p>The WordPress version of the <a href="http://irrlicht.sourceforge.net">Irrlicht website</a> is now live, which means we can edit pages and post news articles using an online editor, users can post comments and we can even appoint community editors to post stuff without giving them rights to the filesystem.</p>
<p>Expect lots more activity there in the future <img src='http://bitplane.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2012/01/irrlicht-website-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2011 in review</title>
		<link>http://bitplane.net/2012/01/mmi/</link>
		<comments>http://bitplane.net/2012/01/mmi/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 10:21:09 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[bitcoin]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[home-brewing]]></category>
		<category><![CDATA[mead]]></category>
		<category><![CDATA[metawatch]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=786</guid>
		<description><![CDATA[Dear diary Sorry for not writing to you of late, but this year has been a busy one.  I&#8217;ll make up for my lack of output with this mammoth post reviewing a small selection of interesting things I got up to this year&#8230; Did far too much work Feels like I&#8217;ve been busting my balls [...]]]></description>
			<content:encoded><![CDATA[<p>Dear diary</p>
<p>Sorry for not writing to you of late, but this year has been a busy one.  I&#8217;ll make up for my lack of output with this mammoth post reviewing a small selection of interesting things I got up to this year&#8230;</p>
<p><span id="more-786"></span></p>
<h2>Did far too much work</h2>
<p>Feels like I&#8217;ve been busting my balls for the last two years, so I decided to stick all my invoices into Google Docs and graph the output. The answer is yes, I&#8217;ve been working like a full-time employee.</p>
<div id="attachment_790" class="wp-caption aligncenter" style="width: 310px"><a href="http://bitplane.net/2012/01/mmi/days-worked/" rel="attachment wp-att-790"><img class="size-medium wp-image-790" title="days worked" src="http://bitplane.net/wp-content/uploads/2012/01/days-worked-300x192.png" alt="" width="300" height="192" /></a><p class="wp-caption-text">2009 was a good year!</p></div>
<p>I love consulting and Microsoft have a great working environment, but a rolling contract at a huge corporation means living out of a hotel for months at a time, which gets old rather fast. I learned a lot about BizTalk, Visual Studio Load Test and T-SQL, I&#8217;ll miss the new friends I&#8217;ve made, but I certainly won&#8217;t miss the travel. So I&#8217;m taking a couple of months off to doss around, learn some new technologies and work on some free software before looking for another contract.</p>
<h2>Rediscovered Bitcoin during the bubble</h2>
<p>I initially flirted with Bitcoin in late 2010 and was completely fascinated by the idea of a P2P currency, specially the proof-of-work method and the anonymity. There was no GPU mining software available and doing work units on the CPU had pretty low returns, but in December I decided to get a decent PC for experimenting with this new currency. After a bunch of cooling problems and losing my wallet.dat (containing a mere 5 BTC, worth about 30 US cents each; £1 total at the time) I fell out of love with Bitcoin and forgot all about it&#8230;</p>
<p>Fast forward 6 months and everyone is talking about this amazing new currency, demand outstrips supply, prices soar and the bubble finally bursts at $28 a piece. Why, oh why did I spend £2,000 on a top of the range computer then not even bother mining any BTC, rather than £1000 on BTC in December and sell out at £95,0000 in June?</p>
<div id="attachment_798" class="wp-caption aligncenter" style="width: 310px"><a href="http://bitplane.net/2012/01/mmi/bitcoin/" rel="attachment wp-att-798"><img class="size-medium wp-image-798" title="bitcoin" src="http://bitplane.net/wp-content/uploads/2012/01/bitcoin-300x111.png" alt="" width="300" height="111" /></a><p class="wp-caption-text">What could have been</p></div>
<p>On top of the new PC the Bitcoin thing ended up costing me about £50 in electricity, and my ATI 5970 hasn&#8217;t been feeling well since. I did play online poker with Americans after they closed all the poker sites, and made about $200 trading on <a title="Magic The Gathering Online Exchange, believe it or not" href="http://mtgox.com" target="_blank">Mt Gox</a>. Not enough BTC to have someone assassinated but the option to buy 5 wraps of heroin from Silk Road is always open (INSTANT ADDICTION, TORE FAMILY APART. A++++ WOULD BUY AGAIN)</p>
<h2>Read Gödel, Escher, Bach</h2>
<p>With all the travel I&#8217;ve had a fair bit of time for reading, which is nice. Along with The Design of Everyday Things and Zen and the art of Motorcycle Maintenance, <a title="GEB" href="http://www.amazon.co.uk/gp/product/0140289208/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=bitplanenet-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0140289208">Godel, Escher, Bach</a> (that&#8217;s Girdle, Esher, Bark to us infidels) changed the way that I think about a lot of things.</p>
<p>This year I&#8217;m going to try to set more time aside for reading.</p>
<h2>Got into home brewing</h2>
<p>A few months back I decided to start brewing mead, yeah, <strong>before</strong> Skyrim came out. I&#8217;m now seven batches in and I think I&#8217;m getting the hang of it, my latest batches taste a bit less like sweaty feet and a bit more like something you might want to drink. I started out using a 5L bottle of water with 3 jars of honey, some raisins and bread yeast added to it and a balloon stuck over the top, and now I&#8217;ve progressed to demijohns with real air-locks and exotic ingredients like.. uh.. orange flesh, cloves and vanilla pods. I even made some labels:</p>
<div id="attachment_791" class="wp-caption aligncenter" style="width: 238px"><a href="http://bitplane.net/2012/01/mmi/mead/" rel="attachment wp-att-791"><img class="size-medium wp-image-791" title="Mead" src="http://bitplane.net/wp-content/uploads/2012/01/Mead-228x300.png" alt="" width="228" height="300" /></a><p class="wp-caption-text">How&#39;s the abdomen?</p></div>
<p>I figure that this whole home brewing thing is a long game, it&#8217;s worth starting while I&#8217;m in my 30s if I&#8217;m going to actually master it before I&#8217;m old and grey. That is if the state of the kitchen doesn&#8217;t cause me to die of death by angry woman first.</p>
<h2>Replaced my MBW-150</h2>
<p>After the LEDs burned out on my Sony Ericsson MBW-150 I replaced it with a shiny new <a href="http://www.metawatch.org/">Metawatch</a>. Apparently it looks like a cheap, tacky Casio (so some random guy in a bar tells me anyway), but it&#8217;s not really supposed to be bling; the firmware and Android software is open source, making the device infinitely programmable.</p>
<p><a href="http://bitplane.net/2012/01/mmi/metawatch/" rel="attachment wp-att-793"><img class="aligncenter size-medium wp-image-793" title="Metawatch" src="http://bitplane.net/wp-content/uploads/2012/01/Metawatch-225x300.jpg" alt="" width="225" height="300" /></a></p>
<p>The down-side is that the firmware is too large to be compiled using gcc for MSP430, so there&#8217;s currently no free development environment. I sketched out an analogue face for it in C, but if I wanted to spend £2000 on an analogue watch face then I would have got a Rolex instead!</p>
<h2>Neglected Free Software</h2>
<p>I&#8217;ve been lazy when it comes to developing this year. I&#8217;ve done no work on my Android apps, pushed a single commit to Irrlicht and wrote about 100 lines of my <a href="http://canvnc.sf.net/">web-based VNC client</a>. I feel like I&#8217;ve cheated on the world by spending most of the year writing T-SQL and C# for Microsoft, so my new year&#8217;s resolution is to get off my backside and write some code.</p>
<p>And blog more. Yeah, I&#8217;ll do that too.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2012/01/mmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anonypic and Microphone source drop</title>
		<link>http://bitplane.net/2011/01/anonypic-mic-source-release/</link>
		<comments>http://bitplane.net/2011/01/anonypic-mic-source-release/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 16:34:01 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android-microphone]]></category>
		<category><![CDATA[anonypic]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[sensors]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=761</guid>
		<description><![CDATA[Since I&#8217;ve not updated these two Android projects in a while, at risk of total future embarrassment (I&#8217;m still a Java newbie) I&#8217;ve decided to dump the source code on GitHub so others can make use of it. Details are on the Anonypic and Microphone project pages. If you fix any bugs, please send a [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve not updated these two Android projects in a while, at risk of total future embarrassment (I&#8217;m still a Java newbie) I&#8217;ve decided to dump the source code on GitHub so others can make use of it. Details are on the <a href="http://bitplane.net/projects/android/anonypic">Anonypic</a> and <a href="http://bitplane.net/projects/android/microphone">Microphone</a> project pages.</p>
<p>If you fix any bugs, please send a pull request and I&#8217;ll do my best to merge them in, but keep in mind this is also my first attempt at using git; expect schoolboy errors there too!</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2011/01/anonypic-mic-source-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import vmstat logs into LoadRunner</title>
		<link>http://bitplane.net/2010/11/vmstat-to-csv/</link>
		<comments>http://bitplane.net/2010/11/vmstat-to-csv/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 19:40:45 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[loadrunner]]></category>
		<category><![CDATA[performance testing]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=731</guid>
		<description><![CDATA[Here&#8217;s a little script to format vmstat&#8217;s output into something you can import into LoadRunner&#8217;s analysis tool: import sys, time &#160; sys.stdout.write&#40;&#34;Date,Time,&#34; &#34;Proc Run,Proc sleep,&#34; &#34;Mem swap use,Mem free,Mem buffered,Mem Cache,&#34; &#34;Swap in,Swap out,Blocks in,Blocks out,&#34; &#34;Interrupts,Context switches,&#34; &#34;CPU %User,CPU %System,CPU %Idle,CPU %Wait,CPU %Stolen\n&#34;&#41; &#160; for line in iter&#40;sys.stdin.readline, &#34;&#34;&#41;: if line&#91;0&#93; != 'p' and [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little script to format vmstat&#8217;s output into something you can import into LoadRunner&#8217;s analysis tool:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Date,Time,&quot;</span>
                 <span style="color: #483d8b;">&quot;Proc Run,Proc sleep,&quot;</span>
                 <span style="color: #483d8b;">&quot;Mem swap use,Mem free,Mem buffered,Mem Cache,&quot;</span>
                 <span style="color: #483d8b;">&quot;Swap in,Swap out,Blocks in,Blocks out,&quot;</span>
                 <span style="color: #483d8b;">&quot;Interrupts,Context switches,&quot;</span>
                 <span style="color: #483d8b;">&quot;CPU %User,CPU %System,CPU %Idle,CPU %Wait,CPU %Stolen<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">iter</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: #dc143c;">readline</span>, <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> line<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'p'</span> <span style="color: #ff7700;font-weight:bold;">and</span> line<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>:<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">' r'</span>:
        t = <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%d/%m/%Y,%H:%M:%S&quot;</span>, <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        line = <span style="color: #483d8b;">' '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        line = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span>, <span style="color: #483d8b;">&quot;,&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s,%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>t, line<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>(Thanks to <a href="http://stackoverflow.com/q/4187785/146642">fabrizoM</a> for the help!)</p>
<p>Run it from a shell script like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">vmstat</span> <span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">|</span> python vmstat2csv.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; servername-vmstat.log</pre></div></div>

<p>Then start the job from the shell, press CTRL+Z and nohup it (so it doesn&#8217;t die if you disconnect) and tail it (so you can keep an eye on it) like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>+  Stopped                 .<span style="color: #000000; font-weight: bold;">/</span>log.sh
<span style="color: #7a0874; font-weight: bold;">&#91;</span>gaz<span style="color: #000000; font-weight: bold;">@</span>box ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">bg</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>+ .<span style="color: #000000; font-weight: bold;">/</span>log.sh <span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>gaz<span style="color: #000000; font-weight: bold;">@</span>box ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">disown</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>gaz<span style="color: #000000; font-weight: bold;">@</span>box ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> servername-vmstat.log
Date,Time,Proc Run,Proc <span style="color: #c20cb9; font-weight: bold;">sleep</span>,Mem swap use,Mem <span style="color: #c20cb9; font-weight: bold;">free</span>,Mem buffered,Mem Cache,Swap <span style="color: #000000; font-weight: bold;">in</span>,Swap out,Blocks <span style="color: #000000; font-weight: bold;">in</span>,Blocks out,Interrupts,Context switches,CPU <span style="color: #000000; font-weight: bold;">%</span>User,CPU <span style="color: #000000; font-weight: bold;">%</span>System,CPU <span style="color: #000000; font-weight: bold;">%</span>Idle,CPU <span style="color: #000000; font-weight: bold;">%</span>Wait,CPU <span style="color: #000000; font-weight: bold;">%</span>Stolen
<span style="color: #000000;">23</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">11</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span>,<span style="color: #000000;">12</span>:<span style="color: #000000;">59</span>:<span style="color: #000000;">47</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">1266452</span>,<span style="color: #000000;">465576</span>,<span style="color: #000000;">2074012</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">2</span>,<span style="color: #000000;">15</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">36</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">99</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>
<span style="color: #000000;">23</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">11</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span>,<span style="color: #000000;">13</span>:00:<span style="color: #000000;">11</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">1264460</span>,<span style="color: #000000;">465584</span>,<span style="color: #000000;">2074024</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">168</span>,<span style="color: #000000;">581</span>,<span style="color: #000000;">577</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">94</span>,<span style="color: #000000;">4</span>,<span style="color: #000000;">0</span></pre></div></div>

<p>When you&#8217;re done, import it into the Analysis tool via the Tools -&gt; External Monitors menu. Make sure you set the correct date for the custom format and remember to keep a close eye on the timezones. If you make a mistake while importing there&#8217;s no going back, so save a backup of your analysis files before you attempt this.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/11/vmstat-to-csv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rainwatch featured on Android Market</title>
		<link>http://bitplane.net/2010/09/rainwatch-top-free-app/</link>
		<comments>http://bitplane.net/2010/09/rainwatch-top-free-app/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 16:34:02 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[rainwatch]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=722</guid>
		<description><![CDATA[Sometime yesterday my app Rainwatch was added to the &#8220;top free&#8221; list on the Android Marketplace, showing in 5th position in the News and Weather section. This is strange because it&#8217;s only 32nd in the &#8220;top free&#8221; list on the market on Android devices, but hey, I&#8217;m not complaining! I guess I&#8217;d better make a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Sometime yesterday my app <a href="http://bitplane.net/projects/android/rainwatch">Rainwatch</a> was added to the &#8220;top free&#8221; list on the Android Marketplace, showing in 5th position in the News and Weather section. This is strange because it&#8217;s only 32nd in the &#8220;top free&#8221; list on the market on Android devices, but hey, I&#8217;m not complaining!<span style="font-size: 13.3333px;"> </span></p>
<p style="text-align: left;"><a href="http://bitplane.net/wp-content/uploads/2010/09/top-free.png"><img class="aligncenter size-medium wp-image-723" title="Rainwatch on Android Market" src="http://bitplane.net/wp-content/uploads/2010/09/top-free-300x264.png" alt="" width="300" height="264" /></a></p>
<p style="text-align: left;">I guess I&#8217;d better make a promotional image for Market and update the screenshots so they actually look like recent versions of the app!</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/09/rainwatch-top-free-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Float.parseFloat is slow</title>
		<link>http://bitplane.net/2010/08/java-float-fast-parser/</link>
		<comments>http://bitplane.net/2010/08/java-float-fast-parser/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 22:17:54 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[performance testing]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=710</guid>
		<description><![CDATA[While profiling some loader code and expecting to see performance issues with my regular expressions, I found that ~60% of my time was actually spent converting String variables to floats. It turns out that the slow bit lives inside Float.parseFloat, where it calls String.toLowerCase every single time just in case this string is a hex [...]]]></description>
			<content:encoded><![CDATA[<p><span>While profiling some loader code and expecting to see performance issues with my regular expressions, I found that ~60% of my time was actually spent converting <em>String</em> variables to <em>float</em>s. It turns out that the slow bit lives inside <a href="http://www.java2s.com/Open-Source/Java-Document/Apache-Harmony-Java-SE/org-package/org/apache/harmony/luni/util/FloatingPointParser.java.htm">Float.parseFloat</a>, where it calls String.toLowerCase every single time just in case this string is a <em>hex float</em>, a very rare type of float which I had never seen before. I <a href="https://issues.apache.org/jira/browse/HARMONY-6635">logged this with Apache</a>, but as I can&#8217;t ship a custom ROM with my SVG parser I decided to replace it.</span><br />
<span>Here&#8217;s the results from some tests of 3896 calls to parseFloat on my Nexus One:</span></p>
<ul>
<li>a) Using Float.parseFloat(String): 1516.449ms</li>
<li>b) My own parseFloat(String): 654.882ms</li>
<li>c) &#8230;and my own isDigit(char): 449.622</li>
<li>d) &#8230;and isDigit written inline: 295.865ms</li>
<li>e) &#8230;copying the string into a char buffer and avoiding all string access and method calls: 254.527ms (112ms spent copying the characters!)</li>
</ul>
<p><span>So in theory, if the method took a character buffer and length it could be as short as 135ms, over ten times faster than Float.parseFloat. I&#8217;m currently using option d as gives a nice performance gain without breaking my design, but when performance tuning the entire API later this may see some huge changes. Here&#8217;s the function I cooked up:</span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">float</span> parseFloat<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> len   <span style="color: #339933;">=</span> f.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">float</span>     ret   <span style="color: #339933;">=</span> 0f<span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;">// return value</span>
	<span style="color: #000066; font-weight: bold;">int</span>       pos   <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>          <span style="color: #666666; font-style: italic;">// read pointer position</span>
	<span style="color: #000066; font-weight: bold;">int</span>       part  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>          <span style="color: #666666; font-style: italic;">// the current part (int, float and sci parts of the number)</span>
	<span style="color: #000066; font-weight: bold;">boolean</span>   neg   <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// true if part is a negative number</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// find start</span>
	<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'0'</span> <span style="color: #339933;">||</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">'9'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'-'</span> <span style="color: #339933;">&amp;&amp;</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span>
		pos<span style="color: #339933;">++;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// sign</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		neg <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
		pos<span style="color: #339933;">++;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// integer part</span>
	<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">'9'</span> <span style="color: #339933;">||</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		part <span style="color: #339933;">=</span> part<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ret <span style="color: #339933;">=</span> neg <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>part<span style="color: #339933;">*-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>part<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// float part</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		pos<span style="color: #339933;">++;</span>
		<span style="color: #000066; font-weight: bold;">int</span> mul <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		part <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">'9'</span> <span style="color: #339933;">||</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			part <span style="color: #339933;">=</span> part<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			mul<span style="color: #339933;">*=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> pos<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
		ret <span style="color: #339933;">=</span> neg <span style="color: #339933;">?</span> ret <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>part <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>mul <span style="color: #339933;">:</span> ret <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>part <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>mul<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// scientific part</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'e'</span> <span style="color: #339933;">||</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		pos<span style="color: #339933;">++;</span>
		neg <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> pos<span style="color: #339933;">++;</span>
		part <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">'9'</span> <span style="color: #339933;">||</span> f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			part <span style="color: #339933;">=</span> part<span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>neg<span style="color: #009900;">&#41;</span>
			ret <span style="color: #339933;">=</span> ret <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>, part<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			ret <span style="color: #339933;">=</span> ret <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span>, part<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span>This is of course a very crude method, it requires a well-formed number and will return 0 or partial numbers instead of raising exceptions, it doesn&#8217;t work with hex floats or parse NaNs or Infinity and it doesn&#8217;t use doubles internally so the accuracy is not perfect. It does however work for my purposes, so I thought I&#8217;d share it with the Internet.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/08/java-float-fast-parser/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Microphone for Android</title>
		<link>http://bitplane.net/2010/08/android-mic/</link>
		<comments>http://bitplane.net/2010/08/android-mic/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 16:48:46 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android-microphone]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[sensors]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=688</guid>
		<description><![CDATA[So, my 4th Android app is out, a simple mic which you can plug into your computer. It&#8217;s got quite a slating on the Android Market because of its latency, the problem is that there&#8217;s quite large minimum values on the buffer size for accessing input and output buffers, there&#8217;s no way to reduce this [...]]]></description>
			<content:encoded><![CDATA[<p>So, <a href="http://bitplane.net/projects/android/microphone">my 4th Android app</a> is out, a simple mic which you can plug into your computer. It&#8217;s got quite a slating on the Android Market because of its latency, the problem is that there&#8217;s quite large minimum values on the buffer size for accessing input and output buffers, there&#8217;s no way to reduce this latency below the ~300ms which it currently has. Hopefully AOSP will address <a href="http://code.google.com/p/android/issues/detail?id=3434">this</a> eventually, paving way for realtime audio applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/08/android-mic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

