<?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>matt.west.co.tt &#187; Javascript</title>
	<atom:link href="http://matt.west.co.tt/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://matt.west.co.tt</link>
	<description>adventures of a retro electro media hacker type person</description>
	<lastBuildDate>Mon, 25 Jul 2011 21:37:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>jasmid &#8211; MIDI synthesis with Javascript and HTML5 audio</title>
		<link>http://matt.west.co.tt/music/jasmid-midi-synthesis-with-javascript-and-html5-audio/</link>
		<comments>http://matt.west.co.tt/music/jasmid-midi-synthesis-with-javascript-and-html5-audio/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 23:40:41 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Demoscene]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=190</guid>
		<description><![CDATA[The executive summary: At last weekend&#8217;s Barcamp London 8, I presented a talk entitled &#8220;Realtime audio generation for the web (because there&#8217;s not enough MIDI on webpages these days&#8221;. In it, I went over the current options for generating audio within the browser, and presented my latest hack in that direction, jasmid: a Javascript app [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The executive summary:</strong> At last weekend&#8217;s <a href="http://eight.barcamplondon.org/">Barcamp London 8</a>, I presented a talk entitled &#8220;Realtime audio generation for the web (because there&#8217;s not enough MIDI on webpages these days&#8221;. In it, I went over the current options for generating audio within the browser, and presented my latest hack in that direction, <strong>jasmid</strong>: a Javascript app that can read standard MIDI files, render them to wave audio (with, at present, some <em>very</em> simple waveforms) and play them directly from the browser, completely independently of your OS&#8217;s MIDI support.</p>
<ul>
<li><a href="https://github.com/gasman/jasmid">jasmid on Github</a></li>
<li><a href="http://jsspeccy.zxdemo.org/jasmid/">Online demo</a></li>
</ul>
<p>Read on for the complete notes/transcript of the talk (in hopefully more coherent form than the talk itself &#8211; next time I promise to spend less time on the flashy demo and more time figuring out exactly what I&#8217;m going to say&#8230;)<br />
<span id="more-190"></span></p>
<p>Right now everyone&#8217;s jolly excited about the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#audio">HTML5 audio element</a>. At last we have a standard-compliant way to drop audio clips into web pages that avoids all the gunk with external plugins and replaces it with a simple tag (well, once you&#8217;ve fought through the details of which browsers support MP3 versus Ogg anyway). It has a comprehensive API to handle all the details of buffering, programatically pausing, playing and skipping and so on &#8211; but one thing it stops short of is being able to generate the audio data on the fly, within the browser.</p>
<p>Why would you want that? Well, I can&#8217;t say why <em>you&#8217;d</em> want it, but I can tell you what I&#8217;m hoping to do with it: I&#8217;m involved in the <i>demo scene</i>, a community of programmers, artists and musicians who create digital art &#8211; something roughly like music videos, but with visuals generated in real time &#8211; and I&#8217;m working on <a href="http://demozoo.org/">a forthcoming website</a> that will showcase those productions. This community originates from the days of the Commodore 64, when people cracked games and added little intro animations to promote themselves, which became more and more elaborate as rival groups tried to outdo each other, until they evolved into full-scale artistic creations and the game cracking side of things took a back seat. And among the artefacts to come out of this community is a hell of a lot of music &#8211; we&#8217;re talking hundreds of thousands of tracks, all preserved in the native formats of the Commodore 64, and the Amiga, and all sorts of other things. And it would be quite neat to be able to play all of these from within my website.</p>
<p>I&#8217;m using this site as an excuse to play around with cool technologies, and at first I figured that this was an ideal job for <a href="http://aws.amazon.com/ec2/">Amazon EC2</a> &#8211; set up a bunch of instances churning away in the background converting these files to MP3. However, when I started to learn about ways to generate audio in the browser, it made sense to take advantage of that and save myself a whole lot of up-front processing (not to mention bandwidth).</p>
<p>At the forefront of this new development is the <a href="https://wiki.mozilla.org/Audio_Data_API">Mozilla Audio Data API</a>, available in the latest nightly builds of Firefox. This extends the HTML5 audio API with a few new methods, the central ones being mozSetup &#8211; which allows you to initialise an empty audio stream with a specified sample rate and number of channels &#8211; and mozWriteAudio, which lets you pass in an array of floats representing some sample data to add to that stream. Like all good up-and-coming browser innovations, we can reasonably assume that once the Mozilla developers have got this API stable enough they&#8217;re going to submit it to WHATWG for inclusion in the HTML5 spec &#8211; but for the moment, it has somewhat limited adoption. There is a remedy for that though&#8230;</p>
<p>At my last Barcamp London, two years ago now, I gave the first public showing of <a href="http://jsspeccy.zxdemo.org">JSSpeccy</a>, my ZX Spectrum emulator written in Javascript, which has been something of a runaway internet hit &#8211; and I&#8217;ve been somewhat surprised by the number of people taking it <em>seriously</em>, rather than as the crazy pointless hack I built it as (not least, the guy who ripped it off and sold it on the App Store as the first ever iPhone Spectrum emulator, despite it running at about 30% speed *cough*). But one guy who&#8217;s picked up the concept of emulation in Javascript and taken it much further than I&#8217;d ever dreamed possible is <a href="http://benfirshman.com/">Ben Firshman</a>, who created <a href="http://benfirshman.com/projects/jsnes/">JSNES</a>, the Javascript <del datetime="2011-02-03T14:19:49+00:00">SNES</del> NES emulator, featuring a whole host of advanced optimisations and new features, including audio support.</p>
<p><img src="http://matt.west.co.tt/images/jsnes.jpg" alt="" /></p>
<p>To achieve this, he created the <a href="https://github.com/bfirsh/dynamicaudio.js">dynamicaudio.js</a> library, which sits on top of Mozilla&#8217;s Audio Data API, but also provides an invisible Flash widget for other browsers to fall back upon. Armed with this work, I was able to build the first step towards my goal: <a href="http://jsspeccy.zxdemo.org/jsmodplayer/">jsmodplayer</a>, a player for the MOD music format originally introduced on the Amiga. It&#8217;s a rather messy format to implement, with every man and his dog coming up with their own custom extensions to it in a very ad-hoc way, but at its heart it consists of a set of uncompressed wave samples (typically a second or two in length), and a script detailing when to trigger them and at what pitch. Put enough of those trigger events together, throw in some effects like volume control and pitch slide, and you have a song.</p>
<p>Now, as we all know from the Apple versus Adobe tiff, Flash is not exactly universal across the platforms we care about &#8211; so we haven&#8217;t covered all of our bases yet. However, for certain applications, there&#8217;s a possible third path (albeit one that I haven&#8217;t properly investigated yet), using another recent browser addition: <a href="http://en.wikipedia.org/wiki/Data_URI_scheme">data: URIs</a>. Unlike typical URLs, which point to some external location that contains the data we want, a data: URI embeds that data directly, as a string of base64 or URL-encoded data. This means that we could generate a string containing a valid WAV file from Javascript (or indeed an MP3 or Ogg file, although generating those from Javascript is a little bit hardcore), and use that as the source of an &lt;audio&gt; element.</p>
<p>This does depend on us being able to generate the audio up-front before starting playback, so it&#8217;s arguably not truly &#8216;real time&#8217; &#8211; something like an emulator, which is generating audio in response to user interaction, couldn&#8217;t really do this. It&#8217;s good enough for our straightforward audio player, though.</p>
<p>For a while there was an unfortunate flaw in this plan: Chrome didn&#8217;t currently support WAV as an audio format. <a href="http://code.google.com/p/chromium/issues/detail?id=23916">The bug tracker ticket relating to this</a> featured some rather flimsy arguments defending this decision, such as &#8220;if we support WAV, people will start widely serving audio across the web as uncompressed WAV files&#8221; (um&#8230; just like everyone on the internet is using BMP files, which are supported by all major browsers, right?). Given the tendency of bug tickets to wander off onto unrelated subjects, it&#8217;s hard to tell what the eventual conclusion to this is &#8211; but if I&#8217;m reading it right, we can happily use WAVs as of Chrome 7.</p>
<p>(At this point, someone rightly mentioned that Internet Explorer imposes a 32K limit on URLs, so that won&#8217;t get you much of a wave file &#8211; especially with base64 or URL encoding to contend with. As such, all we can really do is hope that IE users will tend to have the Flash option available. Personally, I think it makes a refreshing change that we can even <em>consider</em> IE in our cutting-edge browser hacks once again&#8230;)</p>
<p>In fact, there&#8217;s another mechanism for feeding data into URLs dynamically, which I&#8217;d all but forgotten until I started preparing this talk: if you have a &#8216;javascript:&#8217; URL which returns a string when executed, that string will be used as the data. This trick was most prominently used in <a href="http://www.wolf5k.com/">Wolfenstein 5K</a> (long before the wider world caught on to the joys of Javascript size coding contests&#8230;), which constructed its display as an XBM image, an obscure text-based format. Before <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html">canvas</a> came along, I spent many happy hours trying to replicate that trick with GIF images, discovering along the way that Internet Explorer didn&#8217;t like strings containing zero bytes, which sent me down the garden path of constructing valid GIFs containing no zeros. Ah, happy days. In short, I don&#8217;t even know if this works at all with &lt;audio&gt;, and even if it does, it&#8217;s almost certainly as much of a dead end as it was back in 2004&#8230;</p>
<p><img src="http://matt.west.co.tt/images/fpc.png" alt="" /></p>
<p>One project of mine where I really <em>should</em> have seen the value of generating the audio up-front was <a href="http://matt.west.co.tt/demoscene/fake-plastic-cubes/">Fake Plastic Cubes</a>, a demo I wrote this summer to play around with the size reduction tricks I&#8217;d seen coming out of the <a href="http://10k.aneventapart.com/">10K Apart</a> and <a href="http://js1k.com/home">JS1k</a> contests, and to try and come up with something audiovisual in as small a size as possible. On the audio side, that meant ditching samples entirely, and doing the synthesis from first principles, building the sound up from plain sine waves &#8211; but in a classic case of project management fail, I spent a week building a really wonderful synthesiser framework and rushed everything else at the last minute, meaning that I had no chance to actually make something nice on top of it. As a result, it&#8217;s totally unpolished, and the animation keeps stuttering for a split second while it generates the next chunk of audio. It&#8217;s only a tiny fraction of the available processor time, but it&#8217;s enough to be very, very noticeable. I really should have just generated the entire audio track on startup and <em>then</em> kicked off the visuals &#8211; but there was no time for that, or to play around with <a href="http://www.whatwg.org/specs/web-workers/current-work/">web workers</a> which would seem to be another potential way to generate audio as a background process&#8230;</p>
<p>I also didn&#8217;t have time to compose a decent soundtrack, or experiment with the synth enough to come up with interesting sounds, or implement a vaguely sensible way to enter musical notes (as a dodgy workaround, I remapped the names of the notes in the scale to <a href="https://github.com/gasman/fakeplasticcubes/blob/master/src/synth.js">their positions on a QWERTY keyboard</a> and prodded out a melody from those</a>). Fortunately, I didn&#8217;t have to let a good routine go to waste: a week or so back, I encountered <a href="http://www.sergimansilla.com/blog/dinamically-generating-midi-in-javascript/">Sergi Mansilla&#8217;s jsmidi project</a>, which provides an easy way to create standard MIDI files from Javascript. However, it turns out that MIDI support in browsers has more or less stagnated &#8211; while wave audio goes from strength to strength, MIDI is still stuck in the world of OS-specific plugins &#8211; so there was a clear opportunity for some Javascript synthesiser love there. And so I&#8217;ve come up with <a href="https://github.com/gasman/jasmid">jasmid</a>, a JS library for reading MIDI files and playing them back through its own audio synthesis engine.</p>
<p>A MIDI file consists of a simple header, followed by a list of tracks &#8211; each of which is a list of timestamped events, which are usually note on/off events but could be a tempo change, change of instrument or various other things. The timestamps are actually a bit weird: you&#8217;d expect them to be given in something like microseconds, but they&#8217;re actually expressed as a number of &#8216;ticks&#8217;, where the MIDI file specifies a particular number of ticks per beat, and the tempo of the song is given in beats per second, which can change over time just to add further confusion. Ultimately it probably does make sense, because it means you can accurately use any rational number (within reason) as a tempo, and that&#8217;s handy for professional MIDI equipment that has to keep exact time for extended periods &#8211; it&#8217;s just an initial hurdle that you have to get over. Once you&#8217;ve got that in place, a MIDI synthesiser boils down to a set of generator functions that can emit audio waves for as long as you tell them to, and a main loop which picks events off the queue, running the generators until it&#8217;s time to process the next event.</p>
<p>For this first release, the generated sounds are not particularly interesting &#8211; just plain sine waves with a bit of attack/decay volume control applied &#8211; but now that we&#8217;ve got the initial framework in place it should be relatively straightforward to add more diverse sounds, and the synth engine should hopefully be flexible enough to support effects like harmonics and reverb.</p>
<p>Finally, as a glimpse of what&#8217;s in store for in-browser audio creation in the future, keep an eye on the <a href="http://mozillalabs.com/rainbow/">Mozilla Rainbow</a> project, which provides APIs for capturing audio and video from microphones / webcams. For the last few years I&#8217;ve been taking part in <a href="http://fawm.org/">February Album Writing Month</a>, a song writing community where collaborations over the internet play a major part &#8211; perhaps it won&#8217;t be too long until we&#8217;re doing that over a Google-Docs-style online equivalent of Audacity / GarageBand&#8230;?</p>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/music/jasmid-midi-synthesis-with-javascript-and-html5-audio/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Fake Plastic Cubes</title>
		<link>http://matt.west.co.tt/demoscene/fake-plastic-cubes/</link>
		<comments>http://matt.west.co.tt/demoscene/fake-plastic-cubes/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 00:10:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Canvastastic]]></category>
		<category><![CDATA[Demoscene]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=179</guid>
		<description><![CDATA[It was internally nagging me all summer that I ought to release something at Sundown, but apart from some brief excitement around a brainwave I had involving three iPhones, Javascript and some cardboard (which sadly didn&#8217;t work out in practice), it didn&#8217;t really amount to much. Then Evoke happened, and inspired me to decide that, [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center; margin-top: 1em;"><img src="http://matt.west.co.tt/images/fpc.png" width="400" height="300" alt="" /></div>
<p>It was internally nagging me all summer that I ought to release something at <a href="http://sundowndemoparty.org/">Sundown</a>, but apart from some brief excitement around a brainwave I had involving three iPhones, Javascript and some cardboard (which sadly didn&#8217;t work out in practice), it didn&#8217;t really amount to much. Then <a href="http://www.evoke.eu/2010/">Evoke</a> happened, and inspired me to decide that, in the words of Haujobb&#8217;s invitation, <a href="http://pouet.net/prod.php?which=54920">I should</a> make a demo.</p>
<p>Or, to be precise, a Javascript 64K intro. Unfortunately, there was only one week to Sundown by that point, and in a classic case of demoscene project management fail, I spent most of that week building an audio framework, leaving about 24 hours to write the actual demo. The end result is 9K of rather-flaky-performing code, hastily improvised plinky ambient music, and dreadful coder art (except to the extent that I&#8217;ve ripped it off from Fairlight demos).</p>
<ul>
<li><a href="http://fakeplasticcubes.demozoo.org/">Fake Plastic Cubes &#8211; online version</a></li>
<li><a href="http://fakeplasticcubes.demozoo.org/fake_plastic_cubes.zip">Fake Plastic Cubes &#8211; download (10Kb)</a></li>
<li><a href="http://pouet.net/prod.php?which=55778">Fake Plastic Cubes on Pouet</a></li>
</ul>
<p>Still, even if the execution this time didn&#8217;t work out, I think it&#8217;s been a worthwhile exercise in bringing pieces together. <a href="http://blog.nihilogic.dk/2008/05/compression-using-canvas-and-png.html">Jacob Seidelin&#8217;s PNG compression hack</a> (where JS code is stored in a PNG image to take advantage of the compression, then unpacked on a canvas using getImageData) has created a bit of a buzz in the JS development world, but this is the first time it&#8217;s been used in an actual demoscene production (which is surprising, given how the demoscene is the spiritual home of size-coding hacks). Ben Firshman&#8217;s <a href="http://benfirshman.com/projects/jsnes/">JSNES</a> has been dynamically generating audio for some time now, ardently chasing the moving target that is Mozilla&#8217;s <a href="https://wiki.mozilla.org/Audio_Data_API">Audio Data API</a> (with a trusty Flash snippet as a fallback), and <a href="http://www.p01.org/">Mathieu &#8216;p01&#8242; Henri</a> was experimenting with softsynths long before then. Not even my own code is safe from this cherry-picking exercise of doom &#8211; the 3D routines are a mishmash of <a href="http://matt.west.co.tt/demoscene/gallions-reach/">Gallions Reach / Canvastastic</a> (for the lighting model) and <a href="http://matt.west.co.tt/demoscene/antisocial/">Antisocial</a> (for the full scene / movable camera handling). Finally, <a href="http://nodejs.org/">node.js</a> makes a cameo appearance, because having an actual web server on hand makes development go a lot smoother.</p>
<p>Put them all together and you have the ingredients for a delicious 64K Intro cake. This time it came out a bit half-baked, but I&#8217;m passing on the recipe in the hope that someone else can make it work:</p>
<ul>
<li><b><a href="http://github.com/gasman/fakeplasticcubes/">Fake Plastic Cubes source code / framework, on Github</a></b></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/demoscene/fake-plastic-cubes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JSModPlayer &#8211; a Javascript .MOD player</title>
		<link>http://matt.west.co.tt/music/jsmodplayer/</link>
		<comments>http://matt.west.co.tt/music/jsmodplayer/#comments</comments>
		<pubDate>Sun, 23 May 2010 02:22:27 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Demoscene]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=156</guid>
		<description><![CDATA[The epic Pacman 30th anniversary Google Doodle, along with Ben Firshman&#8217;s dynamicaudio.js library for dynamically generating audio, collectively persuaded me that I haven&#8217;t done any mad Javascript hacking for far too long. My response to this state of affairs is JSModPlayer, a player for .MOD music files (the mainstay of Amiga and PC sample-based music [...]]]></description>
			<content:encoded><![CDATA[<p>The epic Pacman 30th anniversary Google Doodle, along with Ben Firshman&#8217;s <a href="http://github.com/bfirsh/dynamicaudio.js">dynamicaudio.js</a> library for dynamically generating audio, collectively persuaded me that I haven&#8217;t done any mad Javascript hacking for far too long. My response to this state of affairs is <b><a href="http://jsspeccy.zxdemo.org/jsmodplayer/">JSModPlayer</a></b>, a player for .MOD music files (the mainstay of Amiga and PC sample-based music circa 1990).</p>
<p>So far it only implements a subset of the possible sample effects, and it demands a very fast Javascript engine &#8211; luckily all the new breed of browsers are pretty competitive at that now. Even so, unless your CPU is an absolute behemoth, it&#8217;ll probably struggle to keep up &#8211; the audio output is fixed at 44100Hz, and that&#8217;s rather a lot of numbers for Javascript to crunch, especially when the MOD file gets up to 16 or more channels. Which, amusingly enough, is exactly the situation we had back when we were using Gravis Ultrasounds on 386es. Hurrah for progress!</p>
<p><strong>Update 2010-06-08:</strong> Oops. In the process of testing how Safari 5 shapes up, I discovered a rather silly oversight: the audio buffering routine was set up to never use more than 10% of CPU. Now that I&#8217;ve fixed it, it turns out that Chrome and Safari (at least) have no trouble at all playing Jugi&#8217;s <em>Dope</em> theme in its 28-channel glory. (However, taking the brakes off the buffering does mean that we can&#8217;t reliably pause the audio any more. A small price to pay, I think you&#8217;ll agree.)</p>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/music/jsmodplayer/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>JSSpeccy v20091121</title>
		<link>http://matt.west.co.tt/spectrum/jsspeccy-20091121/</link>
		<comments>http://matt.west.co.tt/spectrum/jsspeccy-20091121/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 23:12:29 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[JSSpeccy]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Spectrum]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=139</guid>
		<description><![CDATA[Yesterday&#8217;s Full Frontal javascript conference turned out to be the ideal setting to compare notes with Ben Firshman of JSNES fame on the finer points of implementing emulators in Javascript &#8211; so this new release of JSSpeccy is the natural consequence of that. I&#8217;ve put in an optimisation which might possibly be a speed boost [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday&#8217;s <a href="http://2009.full-frontal.org/">Full Frontal javascript conference</a> turned out to be the ideal setting to compare notes with Ben Firshman of <a href="http://benfirshman.com/projects/jsnes/">JSNES</a> fame on the finer points of implementing emulators in Javascript &#8211; so this new release of JSSpeccy is the natural consequence of that. I&#8217;ve put in an optimisation which might possibly be a speed boost on Chrome (only writing bytes to ImageData when absolutely <em>absolutely</em> necessary), and the much-needed ability to load your own snapshot files, using the little-known getAsBinary method on file upload objects. (Unfortunately Firefox 3.5 is the only browser which supports it right now, but it looks like it may be in the process of getting the official W3C blessing right now.) And since I was on a roll, on the train back I implemented tape loading traps and the ability to load .TAP files (again, only on Firefox 3.5). Wahey!</p>
<ul>
<li><a href="http://jsspeccy.zxdemo.org/">Play online</a></li>
<li><a href="http://jsspeccy.zxdemo.org/jsspeccy-20091121.zip">Download JSSpeccy v20091121</a> (680Kb)</li>
<li><a href="http://svn.matt.west.co.tt/svn/jsspec/">JSSpeccy subversion repository</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/spectrum/jsspeccy-20091121/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JSSpeccy v20090929 (Don&#8217;t-Mess-With-Geeks Edition)</title>
		<link>http://matt.west.co.tt/spectrum/jsspeccy-20090929/</link>
		<comments>http://matt.west.co.tt/spectrum/jsspeccy-20090929/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 00:21:19 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[JSSpeccy]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Spectrum]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=127</guid>
		<description><![CDATA[I wasn&#8217;t really planning on developing JSSpeccy further, because I didn&#8217;t consider it a serious project with a future. However, it turns out that someone else did. Enough to rip it off wholesale and pass it off as their own work on the iPhone app store for Â£1.29 a pop, no less. Yes, thanks to [...]]]></description>
			<content:encoded><![CDATA[<p>I wasn&#8217;t really planning on developing JSSpeccy further, because I didn&#8217;t consider it a serious project with a future. However, it turns out that someone else <em>did</em>. Enough to rip it off wholesale and pass it off as their own work on the iPhone app store for Â£1.29 a pop, no less. Yes, thanks to <a href="http://jorallan.livejournal.com/9645.html">the detective work of Phil Kendall</a> we now know that ZXGamer, the much heralded Spectrum emulator for the iPhone, was nothing more than JSSpeccy with a fancy title screen tacked on. (Which of course is a blatant violation of the GPL, and being pure Javascript, would explain why it ran at less than the speed of a real Spectrum on a 600 MHz device, and why it was overwhelmingly rated at one out of five stars. Epic fail.) It&#8217;s been pulled from the app store now &#8211; so while ZXGamer is gradually disappearing from the internet, it&#8217;s time to redress the balance a bit.</p>
<p><a href="http://jsspeccy.zxdemo.org/">A new version of JSSpeccy is out</a>. It doesn&#8217;t run at full speed on an iPhone either (although it positively speeds along on recent versions of Safari on real computers), but it does boast the following changes:</p>
<ul>
<li><strong>GPL v3 licenced</strong>, with prominent notices to make it clear that playing silly buggers like the above will not be tolerated (even if they do include source&#8230;)</li>
<li><strong>A bit of speed optimisation</strong> (about 15% faster maybe)</li>
<li><strong>A pimped-up user interface</strong> with shiny icons</li>
<li>And most relevantly, <strong>entirely controllable via iPhone / iPod Touch touchscreen</strong>. In principle. (If you&#8217;re expecting an immersive gaming experience, you&#8217;ll be disappointed.)</li>
</ul>
<p>So there you go &#8211; probably the best Spectrum emulator for the iPhone ever. And it&#8217;s free.</p>
<ul>
<li><a href="http://jsspeccy.zxdemo.org/">Play online</a></li>
<li><a href="http://jsspeccy.zxdemo.org/jsspeccy-20090929.zip">Download, inc source</a> (674Kb)</li>
<li><a href="http://svn.matt.west.co.tt/svn/jsspec/">JSSpeccy Subversion repository</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/spectrum/jsspeccy-20090929/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JSSpeccy: A ZX Spectrum emulator in Javascript</title>
		<link>http://matt.west.co.tt/spectrum/jsspeccy/</link>
		<comments>http://matt.west.co.tt/spectrum/jsspeccy/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 21:23:26 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[JSSpeccy]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Spectrum]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=110</guid>
		<description><![CDATA[I&#8217;m really typecasting myself here. If there were an international &#8220;Person most likely to write a Spectrum emulator in Javascript&#8221; award, I&#8217;d have taken it for the last five years running. So here it is &#8211; probably the most stereotypical project I&#8217;ll ever come up with. Readme file Run JSSpeccy online (includes 10 classic games!) [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m really typecasting myself here. If there were an international &#8220;Person most likely to write a Spectrum emulator in Javascript&#8221; award, I&#8217;d have taken it for the last five years running. So here it is &#8211; probably the most stereotypical project I&#8217;ll ever come up with.</p>
<ul>
<li><a href="http://jsspeccy.zxdemo.org/README">Readme file</a></li>
<li><strong><a href="http://jsspeccy.zxdemo.org/">Run JSSpeccy online</a> (includes 10 classic games!)</strong></li>
<li><a href="http://jsspeccy.zxdemo.org/jsspeccy-20081019.zip">Download JSSpeccy</a> (644Kb)</li>
<li><a href="http://svn.matt.west.co.tt/svn/jsspec/">JSSpeccy Subversion repository</a></li>
</ul>
<p>Writing this wasn&#8217;t actually such a big deal &#8211; the Z80 core was ported from the one in <a href="http://fuse-emulator.sourceforge.net/">Fuse</a>, with the Perl-and-C-preprocessor-munging trickery still intact, and Javascript is syntactically close enough to C that that wasn&#8217;t a mammoth task. (I got 90% of it done on the train journey back from International Vodka Party alongside <a href="http://matt.west.co.tt/music/5090-2008/#edgware-road">recording silly songs about tube stations</a>.) The one fiddly bit was working around the places where the Fuse code used low-level C constructs to its advantage: using unions to chop and change between individual registers and 16-bit register pairs, and relying on limited-size C data types (often in pretty subtle ways) to truncate 8-bit and 16-bit values at the right time, whereas Javascript only has integers. (Actually, the really time-consuming bit was debugging it all&#8230; luckily, Fuse has a rather excellent test suite too.)</p>
<p>The rest is just creative abuse of the &lt;canvas&gt; element, as usual&#8230; it&#8217;ll take advantage of the putImageData interface to do the pixel pushing if available (on my machine Firefox has it, Safari doesn&#8217;t) and fall back on drawing 1&#215;1 pixel rectangles otherwise. This time I&#8217;ve thrown in Google&#8217;s <a href="http://excanvas.sourceforge.net/">ExplorerCanvas</a> as a nod to those poor unfortunates still stuck with Internet Explorer. Incidentally, I&#8217;d be curious to know how it rates on Google Chrome (I don&#8217;t have an XP/Vista box to test on) &#8211; if the hype is true (and it implements the putImageData interface like all good up-to-date browsers should) then I&#8217;d expect it to comfortably reach 100% Spectrum speed on modest hardware.</p>
<p><i><a href="http://www.movavi.com/opensource/jsspeccy-zx-spectrum-emulyatar-u-javascript">Belorussian translation</a> of this post provided by <a href="http://www.movavi.com/">movavi</a></i></p>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/spectrum/jsspeccy/feed/</wfw:commentRss>
		<slash:comments>89</slash:comments>
		</item>
		<item>
		<title>Antisocial</title>
		<link>http://matt.west.co.tt/demoscene/antisocial/</link>
		<comments>http://matt.west.co.tt/demoscene/antisocial/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 00:08:02 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Canvastastic]]></category>
		<category><![CDATA[Demoscene]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=108</guid>
		<description><![CDATA[This is it then&#8230; my big comeback to the Javascript demo scene after a two year absence, and also the moment when my demo coding muse returned from a long holiday, I guess. Ladies and gentlemen, I give you&#8230; Antisocial, a biting satire on social networking phenomena. Visit the Antisocial microsite&#8230; With my characteristic lack [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/antisocial.png" width="177" height="200" alt="" style="float:right; border:8px solid silver;margin-left: 16px;" /> This is it then&#8230; my big comeback to the Javascript demo scene after a two year absence, and also the moment when my demo coding muse returned from a long holiday, I guess. Ladies and gentlemen, I give you&#8230; <strong>Antisocial</strong>, a biting satire on social networking phenomena.</p>
<p><strong><a href="http://antisocial.demozoo.org/">Visit the <em>Antisocial</em> microsite&#8230;</a></strong></p>
<p>With my characteristic lack of organisation, I found myself with two weeks to go to the <a href="http://sundowndemoparty.org/">Sundown</a> party, having promised a demo release, and with nothing specific in the pipeline. So, I decided to take a chance and run with an idea that had been sitting on top of my &#8220;demos to write when I have more free time than I do right now&#8221; pile for the best part of a year. I had it all planned out in my head, right down to the soundtrack: a mysterious track from an unlabelled CD I picked up at a <a href="http://myspace.com/zxspectrumorchestra">ZX Spectrum Orchestra</a> gig in 2005 (which turned out to be <i>Round</i>, from their Clive Live^3 EP). A quick bit of permission-getting later, and I was at the point of no return.</p>
<p>I knew it would be an ambitious job, and a bit of a leap artistically and technically from my usual stuff. I pencilled in a rough project plan in my diary. I drew up storyboards. I read up on the maths that was too nasty to contemplate on previous projects. And shockingly enough, I actually <em>enjoyed</em> all of the above.</p>
<p><span id="more-108"></span><br />
As it happens, browser technology (as far as the <tt>&lt;canvas&gt;</tt> element goes at least) has not moved on one jot in the last two years, so I was able to dust off the <a href="http://matt.west.co.tt/javascript/canvastastic-beta-1/">Canvastastic</a> codebase and found it still pleasantly usable and not too affected by code rot. I gave it a slightly more OpenGL-ish API (within the limitations of my &#8220;someone at the pub described it to me once&#8221; knowledge of OpenGL) and patched up the more glaring omissions (like Z-plane clipping, so that you can have polygons going behind the camera. Proper <a href="http://www.cubic.org/docs/3dclip.htm">frustum clipping</a> would have been a better idea, so that I didn&#8217;t end up with it trying to plot 20000&#215;40000 pixel triangles and sending Windows into a stroboscopic flashing fit and having to hack up a fix after the party. Macs are fine with it&#8230;).</p>
<p>The demo code was only half the job though; to handle the camera paths and synchronisation and the million other details where hard-coding wouldn&#8217;t cut it this time, I joined the big league of the demoscene by building a demo tool (still all in Javascript) that probably only I can understand. (It&#8217;s included in the final release, so have a play. I dare you.) As I didn&#8217;t have any meaningful experience in 3dMAX, or Flash, or Werkkzeug, or Quartz Composer, or any of the other things I really ought to have been using as reference points, it was a grand exercise in Making It Up As I Went Along. I&#8217;d almost forgotten how much fun it is to code that way, but naturally a fair few bad decisions came out of that as well. Firstly, it turns out that organising things around a timeline interface doesn&#8217;t really fit all that well; it means that every object and event is treated as independent of everything else, so things get a bit clunky when they have to share resources (such as lots of camera shots of the same scene). Looks like you can&#8217;t beat the good old boxes-and-arrows-all-over-the-place approach.</p>
<p>Secondly, and what probably comes as no surprise to anyone but me &#8211; Javascript is a bit horrible for building demo tools in. The demo itself, no problem &#8211; but for the user interface widgets I found myself constantly wishing for nice, sensible class-based inheritance. Yep, I know the language boffins will say that prototype-based OOP is more powerful, but I guess I&#8217;ve just had my mind addled by programming in the real world. I know of a few attempts to graft class-like behaviour onto Javascript, and that should probably be at the heart of any attempted rewrite of this. Alternatively, there&#8217;s a growing-but-not-quite-there-yet buzz around alternative scripting languages in the browser (just like there&#8217;s a buzz in the opposite direction for server-side Javascript), so perhaps it wouldn&#8217;t be out of the question to have a browser demo tool written in Ruby or Python. Or have the browser environment embedded in a ruby/python desktop app &#8211; at which point, why stop at browser demos? Could it be designed as a more general tool, where the browser is just one of many platforms that can be swapped in? It&#8217;s tempting. Onward and upward!</p>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/demoscene/antisocial/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Comet Chaos</title>
		<link>http://matt.west.co.tt/spectrum/comet-chaos/</link>
		<comments>http://matt.west.co.tt/spectrum/comet-chaos/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 00:01:16 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Spectrum]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/?p=103</guid>
		<description><![CDATA[Thanks to Oleg for reminding me at OpenTech that I still hadn&#8217;t written this up yet&#8230; This started out as an experiment in Comet techniques (which allow you to actively push data out from web servers without the client having to initiate the request) which quickly ballooned in ambitiousness &#8211; I didn&#8217;t set out to [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to Oleg for reminding me at <a href="http://www.ukuug.org/events/opentech2008/">OpenTech</a> that I still hadn&#8217;t written this up yet&#8230;</p>
<p>This started out as an experiment in Comet techniques (which allow you to actively push data out from web servers without the client having to initiate the request) which quickly ballooned in ambitiousness &#8211; I didn&#8217;t set out to write Just Another Chat Application after all. The end result is a realtime multiplayer Javascript conversion of the Spectrum wargame Chaos&#8230; or a reasonable chunk of it, at least.</p>
<p><strong><a href="http://chaos.zxdemo.org/">Play Comet Chaos now</a></strong></p>
<p>If you&#8217;re interested in the workings behind it, check out this video from my <a href="http://oxford.geeknights.net/2008/jun-25th/">Oxford Geek Nights</a> presentation to hear about how Comet is like a small child on a car journey, find out how close web developers can get to world domination, and watch a live demonstration going pear-shaped. </p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/zz11l8IlPsg&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/zz11l8IlPsg&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><span id="more-103"></span><br />
Other resources:</p>
<ul>
<li><a href="http://oxford.geeknights.net/2008/jun-25th/talks/microslot-MatthewWestcott.pdf">Presentation slides</a></li>
<li><a href="http://rubyforge.org/projects/shooting-star">Shooting Star</a>, the Rails Comet library</li>
<li><a href="http://shooting-star.rubyforge.org/wiki/wiki.pl?Making_A_Chat_System_Within_5_Minutes">Shooting Star walkthrough</a></li>
<li><a href="http://svn.matt.west.co.tt/svn/chaos/trunk/">Comet Chaos Subversion repository</a></li>
</ul>
<p>But if you&#8217;d rather just dive in and have a play, that&#8217;s fine too&#8230; For those of you unfamiliar with Chaos, it&#8217;s a turn-based game for 2-8 players, each one playing a wizard who has to try and kill of all opponents by casting spells. Most of these come in the form of creatures which you can move across the board to attack opposing creatures and wizards. As ever, <a href="ftp://ftp.worldofspectrum.org/pub/sinclair/games-info/c/Chaos.txt">World Of Spectrum has the full instructions</a>.</p>
<p>Be aware that the current release is rather incomplete and experimental: the repertoire of spells is limited to creatures, &#8216;disbelieve&#8217; and lightning bolts, the combat system is virtually non-existent (everything has a 50% chance of killing everything else), killing wizards isn&#8217;t tested, and the finer points of game mechanics (flying/mountable/undead creatures, ranged combat, law vs chaos) are unimplemented. But don&#8217;t let that put you off&#8230;</p>
<p>An equally important omission &#8211; and possibly the major reason why it&#8217;s attracted minimal user testing and feedback right now &#8211; is that there&#8217;s no way to invite other players, other than marking your game as &#8216;public&#8217; so that it appears on the homepage. (Non-public games still have guessable URLs, though.) To join up with other players you&#8217;ll need to organise things on other channels, such as IRC. Ideally it needs proper user signups, invitations, notifications and friend lists&#8230;</p>
<p>Gosh. I wonder if this could be one of those &#8220;social network&#8221; things all the cool kids are talking about? And that various wise people at conferences say you should never implement yourself, but piggyback on an established one instead? I suppose that means it&#8217;s time for me to swallow my pride and investigate the Facebook and/or OpenSocial APIs soon then.</p>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/spectrum/comet-chaos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZXpaintyONE</title>
		<link>http://matt.west.co.tt/demoscene/zxpaintyone/</link>
		<comments>http://matt.west.co.tt/demoscene/zxpaintyone/#comments</comments>
		<pubDate>Fri, 06 Jul 2007 19:49:54 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Demoscene]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Spectrum]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/demoscene/zxpaintyone/</guid>
		<description><![CDATA[So I wanted to enter the ZX81 Graphic Competition 2007. But I didn&#8217;t particularly want to type out block graphics character by character into a Basic program on an emulated ZX81 keyboard. So I wrote a ZX81 art package. In Javascript. It does make sense &#8211; Javascript is one of the few languages you can [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/zxpaintyone.png" width="300" height="235" alt="" style="float:right; border: 5px solid #cccccc; margin: 0px 0px 10px 10px;" />So I wanted to enter the <a href="http://zx81.republika.pl/">ZX81 Graphic Competition 2007</a>. But I didn&#8217;t particularly want to type out block graphics character by character into a Basic program on an emulated ZX81 keyboard. So I wrote a ZX81 art package. In Javascript.</p>
<p>It does make sense &#8211; Javascript is one of the few languages you can write graphical applications in that&#8217;s truly cross-platform &#8211; as in &#8216;doesn&#8217;t require Windows users to install a massive runtime and a bundle of libraries&#8217;. Well, in this case we do require them to install Firefox, but come on, who&#8217;s going to object to that?</p>
<p>It&#8217;s dead easy to use (painting in three shades of grey is hardly rocket science after all) and it exports directly to ZX81 .P format courtesy of <a href="http://groups.google.com/group/comp.sys.sinclair/msg/eeb95f7af8b5ef5f">a neat Basic snippet from Russell Marks</a>. So if you&#8217;re feeling artistic, give it a go &#8211; you don&#8217;t even need to download it. (But if you do, you get the additional perk of being able to supply an overlay image to trace around.)</p>
<p><strong>Update (2008-07-12):</strong> Now features a handy clickable palette, as requested by Yerzmyey &#8211; so that people with less than three buttons on their mouse can use it. You&#8217;d think that a Mac user like me would have thought of that, really&#8230;</p>
<ul>
<li><a href="http://matt.west.co.tt/apps/zxpaintyone/">ZXpaintyONE &#8211; online version</a></li>
<li><a href="http://matt.west.co.tt/apps/zxpaintyone/zxpaintyone_v2.zip">ZXpaintyONE &#8211; download</a> (ZIP, 8Kb)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/demoscene/zxpaintyone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Canvastastic beta_1 released</title>
		<link>http://matt.west.co.tt/javascript/canvastastic-beta-1/</link>
		<comments>http://matt.west.co.tt/javascript/canvastastic-beta-1/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 22:52:41 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Canvastastic]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://matt.west.co.tt/javascript/canvastastic-beta-1/</guid>
		<description><![CDATA[The loose ends are now tied up and Canvastastic is ready for a not-chronically-rushed release. It&#8217;s now placed under a proper licence (the LGPL) and, more importantly, it has actual API documentation! Download: Canvastastic beta_1 (20K, .tar.gz) If you&#8217;re anything like me, you&#8217;ll probably be turning your nose up at having to download the thing [...]]]></description>
			<content:encoded><![CDATA[<p>The loose ends are now tied up and Canvastastic is ready for a not-chronically-rushed release. It&#8217;s now placed under a proper licence (the <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a>) and, more importantly, it has <a href="http://matt.west.co.tt/files/canvastastic/canvastastic_beta_1/doc/canvastastic.html">actual API documentation!</a></p>
<p>Download: <a href="http://matt.west.co.tt/files/canvastastic/canvastastic_beta_1.tar.gz">Canvastastic beta_1</a> (20K, .tar.gz)</p>
<p>If you&#8217;re anything like me, you&#8217;ll probably be turning your nose up at having to <em>download</em> the thing just to see what the fuss is about, so I&#8217;m happy to oblige with some online demos&#8230;</p>
<ul>
<li><a href="http://matt.west.co.tt/files/canvastastic/canvastastic_beta_1/eg/boxes.html">Boxes</a> (demonstrates lighting and camera movement)</li>
<li><a href="http://matt.west.co.tt/files/canvastastic/canvastastic_beta_1/eg/robot.html">Robot</a> (demonstrates transforms and animation)</li>
<li>and finally, the <a href="http://matt.west.co.tt/files/canvastastic/canvastastic_beta_1/lib/canvastastic.js">library source</a> itself, for those wanting a spot of light bedtime reading.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://matt.west.co.tt/javascript/canvastastic-beta-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

