<?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; Development</title>
	<atom:link href="http://bitplane.net/category/development/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>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>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>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>
		<item>
		<title>Adventures in Android</title>
		<link>http://bitplane.net/2010/08/android-adventures/</link>
		<comments>http://bitplane.net/2010/08/android-adventures/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 05:55:24 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[anonypic]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mc-mail]]></category>
		<category><![CDATA[rainwatch]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=680</guid>
		<description><![CDATA[Since getting myself a Google Nexus One I&#8217;ve decided to do a bit of Android development. My first impressions with the platform weren&#8217;t really that good, but I&#8217;m beginning to get the hang of it now. My main problem is that Java is a horribly verbose and restrictive language. To do the simplest things you [...]]]></description>
			<content:encoded><![CDATA[<p>Since getting myself a Google Nexus One I&#8217;ve decided to do a bit of Android development. My first impressions with the platform weren&#8217;t really that good, but I&#8217;m beginning to get the hang of it now.</p>
<p>My main problem is that Java is a horribly verbose and restrictive language. To do the simplest things you need to implement at least three interfaces and extend a couple of abstract classes (after reading the documentation for each of them and their alternatives of course). Something which could be written in Python in three lines of code and two minutes takes fifty lines and twenty minutes in Java. Perhaps that&#8217;s just me, maybe I&#8217;ve been spoiled by dynamic languages and expect to be able to do things a hundred different ways by just typing whatever comes to mind, rather than carefully considering the available options and planning every step of my app. In my short journey through Java development I&#8217;ve suffered a lot of pain because I make assumptions and choose a design pattern which is incompatible some point later down the line, so I end up refactoring everything ten times before I even get a working prototype. I&#8217;m slowly learning not to fly by the seat of my pants (even if it is the most fun way to fly) and perhaps that&#8217;s a good thing.</p>
<p>My other gripe is the UI editor and XML format, their steep learning curve makes the design stage a huge time sink. I&#8217;ve now spent a fair bit of time banging my head off my keyboard while attempting to make the simplest of interface, which still don&#8217;t look like they do on paper, but I think I&#8217;m getting the hang of it.</p>
<p>Anyhow, so far I&#8217;ve managed to knock out 3 applications which are available in the Android marketplace:</p>
<h2><a title="Anonypic" href="http://bitplane.net/projects/android/anonypic">Anonypic</a></h2>
<p>This little app just adds an extra option to your share menu, and will upload an image to <a href="http://bayimg.com">bayimg.com</a>, the anonymous image sharing service by the creators of The Pirate Bay. Images have their EXIF data removed, so you can share images without leaving a trail of metadata leading back to your phone.</p>
<h2><a href="http://bitplane.net/projects/android/rainwatch">Rainwatch</a></h2>
<p>Rainwatch is an alternative viewer for the BBC&#8217;s Maps Presenter, the Flash application available on their <a href="http://news.bbc.co.uk/weather">weather site</a>. It&#8217;s far from complete but is good enough to predict the weather, so I&#8217;m quite happy with it (as are my 1500 active users)</p>
<h2><a href="http://bitplane.net/projects/android/mc-mail">MC Mail</a></h2>
<p>MC Mail, or Missed Call Mailer is a little app which sends you an email when you get a missed call. The back-end is written in PHP and MySQL, the front-end is mostly just a service which monitors your call log. Useful if you&#8217;re a hospital or call centre worker who has access to email but can&#8217;t use a phone in work, or if you always forget your phone. It usually only works while the phone is in silent mode.</p>
<h2>Next steps?</h2>
<p>I&#8217;ll make a couple more apps and maybe a game, then learn the Native Development Kit and port Irrlicht using Christian&#8217;s OpenGL ES driver. I haven&#8217;t done any Irrlicht code in ages, so that&#8217;s certainly on the agenda.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/08/android-adventures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatic favicon to PNG script</title>
		<link>http://bitplane.net/2010/05/favicon-cache/</link>
		<comments>http://bitplane.net/2010/05/favicon-cache/#comments</comments>
		<pubDate>Sun, 16 May 2010 05:56:51 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PIL]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=583</guid>
		<description><![CDATA[Ever want to add a link to a site with the favourites icon in the page along with the link? I did, so I made this cool little toy:

<a href="http://favicon.bitplane.net/">http://favicon.bitplane.net/</a>
]]></description>
			<content:encoded><![CDATA[<p>Ever want to add a link to a site with the favourites icon in the page along with the link? I did, so I made this cool little toy:</p>
<p><img src="http://favicon.bitplane.net/bitplane.net" alt="" /> <a href="http://favicon.bitplane.net/">http://favicon.bitplane.net/</a></p>
<p><a href="http://bitplane.net/projects/scripts/favicon-to-png">read more&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/05/favicon-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>code_swarm</title>
		<link>http://bitplane.net/2010/02/code_swarm/</link>
		<comments>http://bitplane.net/2010/02/code_swarm/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 21:33:24 +0000</pubDate>
		<dc:creator>Gaz Davidson</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Irrlicht]]></category>
		<category><![CDATA[irrlicht]]></category>

		<guid isPermaLink="false">http://bitplane.net/?p=572</guid>
		<description><![CDATA[I&#8217;ve been playing with code_swarm and made this video of the Irrlicht Engine&#8217;s development history: Since the video is generated from the SVN version history it starts at the point where Niko gave hybrid and I SVN access (June 2006), so misses out years of development leading up to the 1.0 release. code_swarm is a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">I&#8217;ve been playing with <a href="http://code.google.com/p/codeswarm">code_swarm</a> and made this video of the Irrlicht Engine&#8217;s development history:</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/v6j5U-pC8YE" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/v6j5U-pC8YE"></embed></object></p>
<p style="text-align: left;">Since the video is generated from the SVN version history it starts at the point where Niko gave hybrid and I SVN access (June 2006), so misses out years of development leading up to the 1.0 release.</p>
<p style="text-align: left;">code_swarm is a really cool tool, one thing which is exciting is the fact it supports MediaWiki. It would be really nice to show a small wiki coming together.. or maybe one day Wikipedia&#8217;s entire changelog (we can dream!)</p>
]]></content:encoded>
			<wfw:commentRss>http://bitplane.net/2010/02/code_swarm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

