Building a Badass Waveform Visualizer with Adobe AIR and the Canvas Tag

Filed under: AIR, JavaScript

comments (0) Views: 6,097

To build on yesterday's post about Canvas support in Adobe AIR, today's post is going to show the code needed to build a "Badass Waveform Visualizer with Adobe AIR and the Canvas Tag". I put it in quotes because it's that badass. Too many times, the Flash and Flex guys get all the cool AIR stuff. Well us HTML/JS guys are taking it back! You can download the entire source code, which includes the compiled AIR app. Let's look at the code.

Essentially what this code is doing is getting the system's default microphone, then firing off the air.SampleDataEvent.SAMPLE_DATA event. This sends a ByteArray data stream containing a series of floating point numbers between -1 and 1 to the drawEQ method. The drawEQ method then takes those data points and, using the Canvas tag, displays them visually to the users.

I've got this version coded as white strokes on a black background. If you want to spice things up a little bit, we can use random RGB values by taking the following steps:

  • Find var micData = e.data; in the drawEQ function and add this line after it var rint = Math.round(0xffffff * Math.random());
  • In the same function, comment out, or delete, c.strokeStyle = 'rgb(255,255,255)'; and replaec it with this line c.strokeStyle = 'rgb(' + (rint >> 16) + ',' + (rint >> 8 & 255) + ',' + (rint & 255) + ')';

This app was a combination of Ray Camden's post on Microphone support in Adobe AIR, Fumio Nonaka's post on displaying audio waveforms, and my own research into the Canvas tag. What awesome things are you doing with the Canvas tag whether in AIR or not?

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s