Blastanova

May 26, 2011

Embeds are broken in Flash 10.0 with Flex SDK 4.5

Filed under: Uncategorized — admin @ 7:07 pm

I had a big problem today with backwards compatibility and the Flex 4.5 SDK today.

I know….GASP!

But, next let me say that it didn’t have anything to do with the Flex framework, it was an Actionscript 3 project. THAT surprised me.

So what was it? Well, the crux of the issue is that if you use the embed directive to compile in a visual element in your project, said project will completely fail in Flash 10.0.

Here’s what I mean:

Create a new AS3 project. Don’t make it do anything – just embed a graphic.

package
{
import flash.display.Sprite;

public class TestEmbed extends Sprite
{
[Embed(source="myimg.jpg")]
public var myGraphic:Class;
public function TestEmbed(){}
}
}

No – this code doesn’t actually do anything. It just creates an empty flash project with your graphic compiled in. And it works just fine if you test it on your machine.

Now, take that SWF somewhere that you haven’t upgraded to Flash 10.1 yet.

Guess what? The constructor doesn’t even run – instead you get this error:

VerifyError: Error #1053: Illegal override of z in mx.core.BitmapAsset.

I tried the same with library graphics from a SWF – this time I get a problem with mx.core.SpriteAsset.

What is actually happening here?

Well, when you use the embed directive, your source file is actually cast to a BitmapAsset for use in your project. Likewise, your SWF symbol is cast to a SpriteAsset.

These are the trouble classes. Its worth noting that if your project just calls new BitmapAsset(), you’ll get the same problem.

A SoundAsset isn’t a visual element. Lo and behold, instantiating one of those works just fine.

Eventually I narrowed the problem down to playerglobal.swc. Swapping out the 10.0 playerglobal with the 10.2 playerglobal produces the same error.

Lets add this up. It’s a problem with display assets, and the actual error says there’s an illegal override of Z. I’m guessing that the faux 3D that Adobe added in 10.0 where you can set the Z had an API change from the 10.0 player to the 10.2 player.

When you load up your 10.2 SWF in a 10.0 player, that Z getter/setter is so drastically different, Flash just can’t continue.

So – there it is. If you use the embed directive and compile in the 4.5 SDK, your SWF won’t function in anything less than Flash 10.1

April 11, 2011

Cocoon P2P

Filed under: Uncategorized — admin @ 9:52 am

This is just a short post – mainly for myself to remind me of the opensource awesomeness that was just released. It’s called Cocoon P2P.

What this project appears to be is a peer to peer helper application for Flash powered devices to communicate in the same network. So basically, if I have a Android phone, a laptop, and an Android tablet all running Flash on my wi-fi network, they can talk to each other – without a server!

It sounds fantastic, and available at http://code.google.com/p/cocoon-p2p/. The source code doesn’t look that hefty either, so yay for easy to understanding!

January 15, 2011

Use Flash Text Engine in MX Components in ANT

Filed under: Uncategorized — admin @ 3:04 pm

The title of this post is what I googled endlessly for like 2 hours trying to figure out how to do this.

Hopefully you’ll come here when you google this and get the answer you need. For you fine folks, I’ll save you some time. Add this to your compiler options:

<theme dir="${FLEX_HOME}/frameworks/projects/spark" append="true>
     <include name="MXFTEText.css" /> 
</theme>

For the rest of you – maybe you’d like to know what this is or get a little more background.

“Use Flash Text Engine in MX Components” is a setting you can check in the Flash Builder compiler options for a project. Old style Halo (MX) components from Flex 3 use the old text engine.

As of Flex 4, we have a brand new text engine. Unfortunately, Adobe hasn’t completely written all the new components yet for Flex 4 (Spark). This means that your Flex 4 project will probably have a mix of Spark and Halo (MX) components.

One of the most frustrating things about this mix for me is working with fonts. For Spark components, you need to embed your fonts in the Compact Font Format (embedAsCFF=true). For MX components, you need to embed your fonts as non CFF (embedAsCFF=false). This could potentially mean embedding one set of fonts for your MX components and another set for your Spark Components.

Not only does this increase your application size, but it can get really hairy trying to work with styles. You need to identify all components that use Halo/MX components and tell them to use the correct font. If you go low level like label, you need to recognize that things like Alerts are MX components and they use MX labels, while if you just make a Spark label, you’ll be using Spark. So this means creating separate styles for s|Label and mx|Label.

Fortunately, Adobe made a workaround in our MX components. They allow you to use the new text engine in your MX components by checking the “Use Flash Text Engine in MX Components” option in Flash Builder.

While that’s great in Flash Builder, what if you want to use this option outside of Flash Builder? What if you want to do a command line compile, or better yet create an ANT build file.

For the command line option, information is relatively easy to find:

http://help.adobe.com/en_US/flex/using/WSda78ed3a750d6b8f-26a13bbf123c441239d-8000.html

Basically just use the theme argument and add a theme to the compiler options
-theme+=myflexhome/frameworks/projects/spark/MXFTEText.css

This is a special CSS file that Adobe made just for this purpose.

I was a little stumped on how to put it in an ANT build script, though. I tried:

<theme dir="${FLEX_HOME}/frameworks/projects/spark"> 
   <include name="MXFTEText.css" /> 
</theme>

Unfortunately, this completely replaces the theme, and doesn’t add a CSS file to your themes. It worked decently enough for my project (save all the warnings I got).

Luckily another guy on my project, TJ Downes figured out that if you use the “append=true” ANT tag option, you can make this property additive, so you end up with:

<theme dir="${FLEX_HOME}/frameworks/projects/spark" append="true>
     <include name="MXFTEText.css" /> 
</theme>

So there you have it. I couldn’t find this anywhere, so hope this helps you!

May 17, 2010

NCDevCon

Filed under: Uncategorized — admin @ 11:06 pm

Just wanted to post a quick update that I’ll be speaking at NCDevCon with a hands on Flex 4 session on Saturday with Adrian Pomilio, and then on Sunday with a Flash Audio session. Adrian and I will also be pushing our new group Tri-Me! Check out ncdevcon.com for more info on the conference! It’s a great free CF, Flash, Flex, and Web conference in Raleigh

March 24, 2010

Pixel Bender Roundup

Filed under: Uncategorized — admin @ 11:46 pm

Hey everyone,

I just gave a Pixel Bender presentation at our local Adobe User Group yesterday.  Here’s a roundup of the blog posts I wrote as I was collecting my thoughts:

First I wrote about the problems I wanted to solve, and why Pixel Bender seemed like the right choice:

http://www.blastanova.com/blog/2010/03/19/pixel-bending-for-speed-in-flash-and-flex/

Next, an overview and intro of Pixel Bender:

http://www.blastanova.com/blog/2010/03/24/intro-to-pixel-bender/

And then, a post about using Pixel Bender for data instead of images:

http://www.blastanova.com/blog/2010/03/24/using-pixel-bender-to-process-lots-of-data/

Finally, some speed tests along with a sample application I wrote to run the speed tests:

http://www.blastanova.com/blog/2010/03/24/pixel-bender-speed-tests/

Happy Pixel Bending!

Pixel Bender Speed Tests

Filed under: Uncategorized — admin @ 11:38 pm

This is my last in a series of blog posts on Pixel Bender.  I’ll probably be doing one more PxB post when I upgrade to Swiz 1.0 and we’re talking about PxB processors with Swiz, but until then….

This post will be focusing mostly on speed in Pixel Bender and doing similar operations in normal Actionscript.

Pixel Bender is good on speed, pixel by pixel, but there are some operations that make PxB a little less efficient.  In my tests – these efficiency deficiencies are made worse with specific operations.

The worst is when you sample the nearest pixel.  In PxB, sampling one pixel is fine.  But the more pixels you sample as you evaluate one pixel, the worse this problem is exasperated.

Why sample more than one pixel?  Well, a blur effect is a great example.  When you blur, you’re probably averaging the center pixel and the 8 surrounding pixels.  Or downsampling an image…you’d be sampling a whole mess of surrounding pixels and reducing to 1 pixel.  In my audio visualization application, I’m not reasonably going to view 2.5 million pixels.  No, I’m going to reduce down to something that can be displayed – maybe a few thousand, depending on how far I zoom.

In any of these scenarios, I’m sampling more than one pixel.  The more pixels I sample, the worse the performance gets.  In my experiments, it can get to the point where PxB is no better than just doing things in Actionscript.  In these cases, at least Pixel Bender has the whole multi-threaded feature going for it, so your UI performance won’t suffer.

Another horrible aspect of sampling more than one pixel is that PxB for Flash doesn’t support loops and functions.  So, if your kernel needs to sample 100 neighboring pixels, you have to write the 100 lines of code to go with it.

For audio processing, sampling surrounding pixels is the whole point.  The key is finding the right amount of pixels to sample where you get a good average, but still have your Pixel Bender shader running lean and mean.

With that said here’s a sample application which demos performing math operations in Pixel Bender vs performing the same operation in Actionscript 3.

Pixel Bender Speed Test Application

Keep in mind that we keep all the loading of the MP3, and the extraction of the byte array at the very start of the application.  These actually take a fairly long time (almost a full second to extract the audio), but are a necessary evil whether you use Pixel Bender or you don’t use Pixel Bender.  Lets look at the results:

Simple Copy Operation

Take data, and return the same data (but make sure to copy each and every value to a byte array one at a time)

Flash AS3: 1.715 seconds

PxB: 0.475 seconds

Power of 2 Operation (Square a Value)

Take each value, square it, and copy into a new byte array

Flash AS3: 2.81 seconds

PxB: 0.825 seconds

Multiply by 12.54 (a random number I picked for this test case)

Multiply each number by a value and copy to a new byte array

Flash AS3: 1.747 seconds

PxB: 0.495 seconds

Do a Complex Math Operation

Take each value, multiply by 12.54, divide by 100, take the sin of that, and then take the square root of the result.

Flash As3: 3.53 seconds

PxB: 0.713 seconds

Average 10, 20, 50, and 100 values

This is where Pixel Bender should start getting less effective, as we are sampling more and more surrounding pixels.

Average 10 – Flash AS3: 3.727 seconds

Average 10 – PxB: 0.878 seconds

Average 20 – Flash AS3: 3.954 seconds

Average 20 – PxB: 1.153 seconds

Average 50 – Flash AS3: 3.613 seconds

Average 50 – PxB: 2.047 seconds

Average 100 – Flash AS3: 3.636 seconds

Average 100 – PxB: 3.469 seconds

As you can see, Pixel Bender does VERY well until you start sampling more and more neighbors.  As we reach 100 neighboring pixels sampled,  there really is no speed advantage to Pixel Bender.  Fortunately though, we’re still talking about an operation on a different thread that won’t slow down the UI.  So even if it does take 3 and a half seconds, its 3 and a half seconds of time that our UI is as snappy as ever.

Remember before when I talked about extracting your audio?  Well, you don’t have to grab 60 seconds all at once and lock up your UI for a full second.  You could grab less, and process the audio in increments.  With PxB, you can just keep running shader job after shader job.  You’ll have to determine what’s best for your UI vs how fast you want the operation to complete.

Another thing that I’ve hidden (though I didn’t mean to)  in this demo application is the time it takes to create the Shader.  I’ve found that it takes around one second to create a Shader.  This means that before you utilize a Pixel Bender kernel, you must take 1 second of unresponsive UI time to have a shader be created.  Creating a ShaderJob, on the other hand takes about a millisecond.  This means that you could spend 1 additional second at the beginning of your application to initialize the shader.  That’s one second of time that you didn’t have to spend running your AS3 only code.  However, the more ShaderJobs you have to split up the work, the more this 1 second becomes a moot point.

An additional note of interest is the shaderJob.start method.  By default, the parameter you pass in here is “false”.  This boolean indicates whether to “waitForCompletion”.  If you don’t wait for completion, then you are using this event asynchronously – meaning you assign an event complete listener and wait for the operation to complete while your code does other things.  If you specify the “waitForCompletion” flag as true, then all Flash operations will halt until  your shader job finishes, and you don’t have to set an event complete listener because the next line of your AS3 code will just execute after the job completes.  I’ve read that this can give you a slight speed increase, but I haven’t had this experience.  Plus it will lock up your Flash code execution until it completes, meaning your UI will be unresponsive.

And that completes my series of posts on Pixel Bender for now.  Kevin Goldsmith at Adobe has been doing some pretty cool stuff as well.  He does audio processing live, or rather each time Flash reaches into the audio buffer to get the next sound samples.  So he actually uses Pixel Bender to alter audio AS YOU PLAY IT.  So that’s very cool, check it out here.

There is much more to this Pixel Bender stuff.  Find it online, and especially read up on the Pixel Bender Twiiter account.  For now though, I’m done.  Happy Bending!

Using Pixel Bender to Process Lots of Data

Filed under: Uncategorized — Tags: , , , , , — admin @ 11:38 pm

In my previous post, I talked about using Pixel Bender in the way it was intended.  By this, I mean to input an image, change the pixels in some way, and output an image.  As you might be aware, this can happen very quickly and be used to create some great run time visual effects in Flash and Flex.

What piqued MY interest in PxB though, was the fact that the you didn’t have to send it an image to process.  It could be any ByteArray object.  My interest was a little bit more specific – a ByteArray extracted from a flash.media.Sound object.  At 44,100 samples per second, with typical MP3 files being 180-200 seconds, we’re talking about pushing 10 million samples.

My project involves visualizing the waveform of a song, so I want to process all of these samples at once, and as quickly as I can.

So, lets look at how you would normally apply a PxB shader.  The following example is taken from Mike Chamber’s blog:

import flash.filters.*;
import flash.utils.ByteArray;		 		
 
//the file that contains the binary bytes of the PixelBender filter
[Embed("testfilter.pbj", mimeType="application/octet-stream")]
private var TestFilter:Class;		 	
 
private function onApplicationComplete():void {
//Pass the loaded filter to the Shader as a ByteArray
var shader:Shader = new Shader(new TestFilter() as ByteArray);
shader.data.amount.value = [100];
var filter:ShaderFilter = new ShaderFilter(shader); 	
 
//add the filter to the image
im.filters = [filter];
}

So, Mike’s got the right idea here. He creates a shader, makes a shader filter out of it, and then applies it as a filter to the image.

We’re going to be doing something slightly different. Instead of a ShaderFilter, we’ll be creating a ShaderJob. And we’ll also need to tell our ShaderJob certain things that our ShaderFilter knew automatically. Specifically, we’re talking about the height, width, and input source of the image. After setting these properties you add an event listener to the job, and tell it to start.

var output:ByteArray = new ByteArray();
data.position = 0;
 
var channels:int = 4;
var width:int = 2000;
var height:int = data.length / width / (channels*channels);
 
shader.data.src.width = width;
shader.data.src.height = height;
shader.data.src.input = data;
 
var shaderJob:ShaderJob = new ShaderJob(shader, output, width, height);
shaderJob.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
shaderJob.start();

OK, I’ll back up…it’s a lot to start with. Let’s talk about the input data first – our byte array.  Because I’m talking specifically here about a byte array extracted from sound, I know that my byte array is a long list of 4 byte floating point numbers.  This particular list of numbers alternate from left channel to right channel, but that’s neither here nor there until we get into the Pixel Bender kernel.

So, now we’re talking the language of Pixel Bender – a byte array of 4 byte floats.  Now, we’re typically we’re dealing with 4 of these 4 byte floats (formerly known as red, green, blue, and alpha).  I believe that PxB is SUPPOSED to accept image1, image2, image3, or image4 type inputs, however I’ve read there are bugs associated with doing anything less than image3 as the input.  Even if we wanted to take advantage of an image2 – think about it.  PxB is designed to process a pixel as fast as it can,  Why not take advantage and create the largest pixel we can?  Little decisions like this multiply in big ways when you start talking about your entire data set, and you could be talking about saving hundreds of milliseconds for these little decisions.

So, each pixel is 16 bytes.  In my sample code, I’m calling out 4 “channels”.  This is an important variable when thinking about our height and width.

Let’s talk a little about height and width now.  As you know, an image has a height and width.  But how does this apply to a one dimensional list of items for PxB?

It all comes down to speed and optimization.  You could certainly give your data input a height of 1 and a width of 8192 (the height and width limit) and treat your data as a one-dimensional list.  It’s certainly easier to picture that way, but then you wouldn’t be taking advantage of PxB’s built in speed and optimization.

Pixel Bender is multi-threaded, multi-core, and GPU enabled.  While that last part doesn’t hold true for Flash, the first two parts are important.  Not only can PxB itself operate on a different thread and CPU core, so can each row of data.  So, PxB can be processing many rows of pixels all at the same time.  If you only do one row per job (a height of 1), you’re throwing away most of the speed benefits of Pixel Bender!  The data itself will wrap around to the next row, just like a text field wraps text to the next row.

How does you know what width and height to give your data?  Well, with a possible width and height of 8,192, you’re giving yourself a possible 67 million pixels to work with in one job.  Each one of these pixels holds 4 channels.  Which means, in one job you can process 268 million floating point numbers.

Earlier I had talked about each MP3 file being around 10 million samples.  I’m personally conducting my own speed tests, but I’ve found that processing 60 seconds of an MP3 file at a time is a little better overall for speed.  So we’re only talking about 2.5 million samples that I would personally process at a time.  So, now the question becomes: How can we reasonably distribute our data as an image.  Well, if we max out our width, we may not be producing many rows.  As  a result, speed may be reduced because we’re not utilizing multiple threads as efficiently as we could.  Based on my input data, I’ve found that a width of 2000 works well for me based on the specifics of my application.  Your mileage may vary, so feel free to try different things.  Just remember, you’ll want to take advantage of many rows for PxB optimization.

And then of course, to get the height, you can work that out by calculating this from your width and the overall length of your byte array.

After all has been said and done, you start the job, set the event listener and wait for the job to complete.

Next up, I’ll be posting some speed tests!

February 3, 2010

Retiring yellow5labs.com, launching blastanova.com

Filed under: Uncategorized — admin @ 7:24 pm

Oh so long ago (2001 maybe?), I started yellow5labs.com.  I had been recently laid off, and wanted to set myself up with an online identity to get contract work and look all flashy so people would hire me.

The name yellow5labs was inspired from Yellow #5 food dye.  You know, that stuff…that you put into twinkies, and doritos, and all sorts of good stuff to give something plain that extra pizazz.  I was kinda thinking I would sell it as I was bringing that pizazz to my interactive work.  I still think it’s a pretty cool name, except it’s horribly impractical.

Every time I have to give my email address, I have to say “yellow…..five…..no, the number five, don’t spell it out, labs.com…..no, I don’t have 5 Golden Labrador retrievers…..no…FIVE….don’t spell it out…”

It got a little tiresome.  The site is still up, but I’ll probably just let the domain lapse this summer.

Anyway, in with Blastanova.  If you hear it, I think you’ll know how it’s spelled, and that should save me a lot of grief.  Why blastanova though?  Well, lately I’m both fascinated with the idea of music based video games, and sad that I don’t like music as much as I used to.  I think a lot of it has to do with the fact that I’m not forced to use the CD player in my car anymore, and I have an unlimited amount of music.  So songs are almost disposable now, and no real connections are made with the artists, because you aren’t listening over an over again to the same disc.

I think games rhythm games (like Rock band most recently), really get you listening to the songs over and over again, and really establishing a connection between you and the music.

So – “blast” as in blasting stuff in video games…..and “blastanova” as in bossanova, a music that literally translates to “new beat” and derived from Samba which itself is known for it’s rhythm.  I dig.

In the short term, I’ll be blogging on new media, developing for the web, Adobe’s Flash & Flex, and bands I’m listening to.

In the long term, I’m developing an application to scan songs and their rhythm and structure, and soon thereafter, I’ll be applying the data to games I develop.

So that’s the plan.

September 2, 2008

Lame comic attempt after watching the RNC

Filed under: Uncategorized,personal — admin @ 11:38 pm

No its probably not very funny – but I got bored with code tonight and the RNC was on with Fred Thompson talking about how McCain POW camp stay….Terror Cats - Vs - McCain

Powered by WordPress