Archive for the 'Uncategorized' Category

Random thoughts on Vectors and samplesCallbackData

I have had reason to play around with some of the new functionality of Flash Player 10 and the vectors is just awesome.
On top of the benefits of the strict typing they are about 50% faster than Arrays according to my tests.

Being completely new to the concept, how to create multidimensional vectors was not completely obvious since you need to type every dimension when declaring the bottom level dimension:


var v1:Vector.<Vector.<Vector.<int>>>= new Vector.<Vector.<Vector.<int>>>();
var v2:Vector.<Vector.<int>> ;
var v3:Vector.<int>;
for (var i:int = 0; i < 10; i++) {
	v2 = new Vector.<Vector.<int>>();
	for (var ii:int = 0; ii < 10; ii++) {
		v3 = new Vector.<int>();
			for (var iii:int = 0; iii < 10; iii++){
				v3[iii] = iii;
			}
		v2[ii]=v3;
	}
	v1[i]=v2;
}

 

So far I have mostly been experimenting with the new samplesCallbackData to create a little mixer.
It seems like one needs to bypass the mixer in the Flash Player if one want to write to the output buffer because creating several sounds and then doing samplesCallbackData.writeFloat() on them will not work.
Of course each channel doesn't have its own output buffer, so you can only write to the master output.
The problem I'm having with this is that if one would like to have a level meter for each individal track I cannot figure out a way to determine what sample is currently being output.
Here is a simplified version of how I implemented the mixing in the SamplesCallbackEvent handler:


var i:int = 0, l:int = _sounds_vect.lengt;
while (i < l) {
	samples = new ByteArray();
	samples.position = 0;
	snd = _sounds_vect[i];
	snd.extract(samples, _bufferSize);
	_samples_vect[i] = samples;
	_samples_vect[i].position = 0;
	i++;
}
while (c < _bufferSize) {
	left = 0;
	right = 0;
	i = 0;
	while (i < l) {
		valL = _samples_vect[i].readFloat();
		valR = _samples_vect[i].readFloat();
		left += valL;
		right += valR;
		i++;
	}
	valL = left;
	valR = right;
	_out_snd.samplesCallbackData.writeFloat(valL);
	_out_snd.samplesCallbackData.writeFloat(valR);
	c++;
}

So the audio is mixed in chunks the size of the buffer and then written to the buffer using samplesCallbackData.writeFloat().

 

For the main output I can create a level meter using:


_out_chn = new SoundChannel();
_out_chn = _out_snd.play();
function onEnterFrame(e:Event):void {
	_masterSlider.drawLevel(_out_chn.leftPeak, _out_chn.rightPeak);
}

 

But for the individal channels I will never issue a play() and hence cannot find a way to get a really consistently behaving level meter or spectrum.
I'm sure there is some clever way to do it that is escaping me.

 

What I currently do is to get the value in the mixing loop like so:


while (i < l) {
	valL = _samples_vect[i].readFloat();
	valR = _samples_vect[i].readFloat();
	left += valL;
	right += valR;
	if (c == 0){ // tried with (c == _bufferSize - 1) and (c == _bufferSize/2) as well
		_levelR_vect[i] = valL;
		_levelL_vect[i] = valR;
	}
	i++;
}

I then use the _levelL_vect and levelR_vect values in my onEnterFrame handler to draw the bars, but the result is a lot less accurate than what is possible using my_chn.leftPeak and far from satisfactory.
I guess what I would need is a way to be able to tell what sample from the output buffer that is playing a certain moment in time.

 

Apart from that small issue it's great to have the functionality to generate and process audio and I think we will see some very cool applications appearing eventually.

Stupid keep it simple?

Simplicity, accessibility and content should always be the main focus when you design, at least that's what we are usually told. But are they actually only factors to consider and sometimes they can be somewhat disregarded in favour of other considerations?

Many times when discussing various aspects of graphics or software design I find that a lot of people love to deal in absolutes. They catch on to some idea that might contain a lot of truth and it becomes a mantra that should be obeyed at all times and at all costs.

 

KISS

Keeping it simple is certainly good advice, both when it comes to programming and design.
But this doesn't mean that simplicity always should be the first priority.
For example if we look at desktop applications targeted at professionals a lot of audio and graphics software is very complex. You can't just dive in to 3dsmax or Logic Audio and get immediate results. Sketchup or Reason for sure wins over the pro-end software in terms of simplicity.
But many pros or more dedicated enthusiasts do need more features than the simpler software provide and they are prepared to invest some time studying the applications to discover functionality that will speed up their work flow or improve the results.

With the web people often have little time and patience to figure out a complex interface, so many times simplicity is very important. But it's always a balancing act, and there is not ultimate truth that the simpler the better a website is. The need for simplicity depends a lot in the target audience and intended purpose. If it is a RIA where people will come back and use it many times and are likely to be willing to spend time to overcome the complexity it can be worthwhile adding features that initially may confuse the users somewhat if they are likely to understand it and find it useful after the initial learning curve.

 

Accessibility

Something I hear very often is statements like "excluding even 1% of the visitors should be avoided". Usually this is said when discussing using Javascript or Flash on a web page.
In many cases one can use progressive enhancement and then i think one should try to do so to avoid excluding anyone, but in some cases it's simply not possible.

Let's for example say that you have a e-commerce website that you are considering to implement a RIA where people can design their own product. Doing it in HTML would mean a really tedious process of typing in values in fields and on each change reload the page to see the result.
Of course it's not worth making the experience horrible for 99% just to make sure that the one 1% without the technology needed to access a reasonable implementation should have to suffer.

You simply cannot just count on how many customers you loose because they are not able to use your application, you also have to evaluate how many you will gain by having something that is really usable for the vast majority of visitors.

And lets not even mention where for example youtube would be today if they decided that they cannot rely on any technology that doesn't have 100% coverage.

 

Content is king

Sure the internet is mainly about information and entertainment, but there are examples of successful sites that have hardly no content.
No, I don't count milliondollarhomepage. Despite being successful it's too stupid to prove a point.

But some sites mostly deal with branding and the content is actually not that important.
How many people have visited 2advanced.com because of the content?
Still I would guess it's a very successful site when it comes to achieving it's goals and that it has done a lot to promote their services. Not thanks to the content but almost exclusively due to the looks.

 

While all of these mantras are very important aspects when it comes to design I think it's important to see them as factors rather than absolutes. It's not always easy to evaluate how much complexity your users will appreciate or how much a certain technology can add and compare that to the impact of that to excluding some visitors.
But it's always about trying to find a correct balance and thinking that there is one answer for every scenario is fooling yourself into thinking reality is simpler than it is.

Site update

I have been meaning to upgrade my site for quite a while now, but since I just haven't had the time to spend on fixing up and redesigning my flash site so it's up to standards I decided to replace it with a simple wordpress blog for now.
And I must say I'm quite happy with functionality of it, and adhering to the old "content is king" mantra the first thing I will do is taking up blogging again and spend some time making applications for download.

I have copied the old posts from the BlixtBlog, but I could not be asked to transfer all the comments.
So my apologies to everyone who has been posting...if I make a new Flash-based blog system I will use wordpress for the back end and make sure the same thing doesn't happen again.

Right tool for the job…or right job for the tool?

Usually when people discuss Flash, AJAX and HTML there will be a lot of people saying "just use the right tools for the job, both have their strengths."
Seems obvious enough and makes sense.
But do we really have to learn to use all tools, and could one not turn it around to say that we should find jobs that fit our tools?

I many times been thinking I should have a look at AJAX because I might get a project where it would be a good solution.
The main reason I haven't bothered is that I have problem finding uses for it where Flash is in any way inferior. The only reason to go with AJAX that I can see is if you have a HTML page where AJAX could feel more visually integrated, but on technical merits alone I find it hard to see where AJAX would be a better tool.

The point I'm trying to make is not about if Flash is better than AJAX.
Regardless of the merits of using AJAX vs. Flash I really dislike having to deal with browser issues and a far from ideal development environment

Sure, if there was no demand for Flash and I had to make sure to put food on the table, then an AJAX job might seem tempting.
But as we all know Flash is higher in demand than ever, so why would I start using a technology that I don't enjoy working with that basically fills only fills some of functions as the one I already master?
To make sure that I can give the best solution to a customer who have a project that is one of the few where I think AJAX would be a better choice?
No thanks, if that situation would arise I'll be happy to send them on to someone who likes to deal with browser incompatibilities.

As long as I have the possibility I rather choose jobs where my skills is the right solution. Sure I like to keep up with new technologies, but only as long as they seem nice to work with and they bring new advantages. But to choose what tools to use according to the jobs on offer doesn't appeal to me.

So, what's your approach, choosing the skills that you find nice and useful to find matching jobs or adapting your skill set to the jobs on offer?

Back

It's been a while since the last update.
First of all I had a little daughter in april...Disa:

I won't blame her for the lack of updates to the blog and the systems available on the download page though. She's been amazing and hardly ever create a fuzz....a real little angel.

But I've been enjoying the excellent summer we had in Sweden with the family and also had a lot of work, both with development and around the house.
I will try to better now and make some blog posts, add some recently done projects in the portfolio as well as maybe release updated versions of the systems.

Web 3.0

Ok, I know there seems to be enough difficulties defining what Web 2.0 actually means.
So of course attempting to define what web 3.0 will be is silly, or if you are enough of a visionary will make you stinking rich and renowned.
I guess I will fall into the silly category, but I do like to speculate (although I would prefer to become stinking rich and renowned) :)

I must say I would have completely failed perceiving what web 2.0 would be about a few years ago.
It took me ages to see what is so useful about XML and syndication, and I'm still neither a flickr or del.icio.us user. I recently started blogging and the only typical web 2.0 service I actually is using is audioscrobbler, or last.fm as they are called now.

So my speculations about the future is similar still to what I was foreseeing in the end of the 90's. Maybe I'm looking to far into the future or looking in the wrong direction.
But anyway...here we go....the future of the web according to me:

AI
This is the big one I think.
I guess the first thing at least I think about when I hear AI is robots, or translated into a web environment, avatars.
And I do imagine we will see a few sales or support avatars and get just as annoyed with them as with the MS search puppy.
But in essence what those avatars will be is kind of like search engines that analyse how you interact with the website or respond to questions you ask them.
So the main area where AI will be useful is to behind the scenes modify what the user is presented with. The websites will turn intelligent and guide us to the information we need, or the products we don't need but maybe can't resist.

How would that work?
Take a shop, for example amazon.
The already have a lot of functionality that will customize the content and give you suggestions based on for example "people who bought this book also bought.."
Now take that a step further and have the website registering how long users look at different items to try to measure their interest and serve content based on that.
Maybe use different descriptions targeted at different types of customers based on their browsing and purchase habits. Just like a good salesman would adjust the pitch after making a judgement on what the needs and desires of the customer is.
For example a customer who just bought "flash for dummies" that looks at "actionscript bible" could like to know that it has many chapters really useful for complete beginners while the seasoned actionscript developer might be turned of by knowing that.
Ok, sneaky I admit, but just like a real sales person would do in most cases.
Of course it should be used to find the right product for you and not try to sell you anything you look at.

I'm sure for example google is exploring AI techniques for their search engine.
What do users that search for a certain phrase usually click on?
I don't know if google does calculate on that yet, but it seems to me like a sensible way to have the users actually weed through the results for them.
Are European users maybe more likely to click on some results compared to Americans or Asians?
I know I been annoyed trying to find a shop in the EU when looking for some products.
If google as clever it would presume that since I'm based in EU, and other people from the EU that have been searching for a place to buy American Spirit tobacco went for a result that was a shop not based in the US, it should prioritize those results for me.

Interactive Multimedia
Web 2.0 started changing things a bit, but how many pages isn't still basically an on-line brochure with the only difference that you click a link instead of flicking page by hand?
As bandwidth increases and the technologies like Flash matures I think internet will develop more into being a medium with it's own style.
Not just put some text here with an image there, a link there and maybe if you feel extremly adventurous a video there.
The web has potential to be extremly immersing and efficient in getting messages across and promoting products or services by combining advanced interactivity with all kinds of media, and I think we will see more and more examples of how to do that.

VR
Yes, I know....it was hot in the beginning of the 90's and just never took off.
Or did it? On-line multi player gaming is Virtual Reality even if you don't have the full lawnmoverman-outfit and is immensely popular now.
Maybe for example virtual shopping malls where you can try an outfit on your avatar before buying it could be one possibility.
Environments combining gameplay, social networking and real life interaction like shopping maybe could prove successful, although I guess most people like to keep them separate.
So maybe VR will remain something that is used mostly for game play, but nevertheless it will be a big part of the on-line experience.

AS3 computeSpectrum and FFT not working?

I was very excited to notice that you now with AS3 can retrieve amplitude and spectrum information. I been hoping for this for a long time, and now it's there :)
Problem is that it doesn't seem to work properly.

I looked at the example on www.richapps.de and tried it out.
The problem is that accessing the values of the byteArray with normal array access brackets will not give the correct values.
It will return the byte value, ie a value between 0 and 256. According to the documentation for AS3 the computeSpectrum should return a decimal value between -1.0 and 1.0.
So since the length of the byte array is 2048 and the number of values should be 2x256 the values is stored as a single-precision 32-bit value.
So that gives that each value should be stored in 4 bytes and that readFloat would be the appropriate method to retrieve the values.
So my code to read the array for the right channel looks like this:

while(i>1024){
   spectrum.position=i;
      sprites_array[Math.round(i/4)].scaleY=(spectrum.readFloat()*100);
   i=i+4;
}

That works fine when FFTMode is false.
It will display the raw wave as you can see in this example.
(requires flash player 8.5, click to start sound).

But what you usually want to do to display a spectrum is to use FTT.
That will analyse the wave and actually make it into spectral information.
So, I try with just setting FFTMode to true....but no luck :(
Here is the swf with FFT applied.
As you can see there is no spectral information. With a sine sweep like this what you should see is a thin spike travelling from right to left.

Am I doing it completely wrong, or is indeed the FFTMode not working as it should?
Someone managed to get it to display a proper spectrum graph yet, and if so how?

BlixtBlog up and running

Welcome to BlixtBlog.

In this space I will provide my rants and ramblings, mainly about Flash and everything related.
First off a little about the system itself.

It's a fairly simple Blog/CMS system using Flash for the front end and PHP/MySQL server side.
I'm planning to release it as open source very soon.
I just want to tidy up the code a wee bit before letting it out in the open.
Why a flash based blog system you might wonder?
Being a flash fanatic the primary reason is that I use a flash based site, and hence like a system I can incorporate into the site.

The advantages as I see them with a Flash based system are:

  • Integrates into existing Flash sites.
  • Can be used as a simple CMS system for not so scripting savvy designers to make attractive but manageable sites.
  • Accordion style links on the side for ease of navigation.
  • Using coded graphics makes resizing text look ok.
  • Coded graphics also give easy customization of colour scheme combined with lightweight file size.
  • Of course there are downsides compared to an HTML based solution:

  • Image handling is poor. You can get decent results but you have to be aware of pitfalls when updating the site so images don't overlap or obscure text.
  • Only non-progressive jpgs is possible to use. I will maybe code a solution to import other formats....or I might just wait for Flash 8.
  • HTML version need to be set up for search engine indexing and users with screen readers or without flash. Since it don't need to be fancy looking that is a simple task, and a script to output the blog as html will be included in the package.
  • I managed to make a fairly solid state management solution for deeplinking, bookmarking and back/forward button functionality, but it's still not compatible with all browsers.
  • Anyway....I'm quite happy with the features it has and think it's great to use in a flash site.
    Please try it out and tell me what you think needs to be improved.
    I'll get on with tidying up my code and creating the component package now.