Synthesizing Sound in Flash

I've been tinkering with sound synthesis using Flash. This wasn't possible before but, with Flash 9 player, one can do using Loader.loadBytes to create and load SWF files (containing sound or whatever) from within a running Flash movie. You can find details and some code at FlashCodersBrighton blog.
Aside from CPU load affecting sound and random clicks from timing mishaps, I think this method is too slow because a movie has to be created every time a sound channel needs to be filled again and, at 44K samples per second, even Flash 9 JIT-compiled code will start to sweat if buffer is too small. And, if buffer is too large, latency will affect the sound output. Also, since a 16-bit stereo track will need a 176K buffer for 1 second of sample data, memory requirement for multi-track real-time synthesized music becomes problematic.
One short-term solution is to give up the nicety of assigning a SoundChannel to each track and mix internally so that only one SoundChannel is used as output. I think this is how André Michelle got relatively good performance with his synthesized drum demo because I had trouble getting similar result using per-track SWF loading. Track-specific pan and stuff has to be done manually instead of relying on SoundChannel though. Also, even André's demo has problems on slow or old machines.
In conclusion, I don't think it makes much sense to dance on this particular bleeding edge when the next version of Flash could have built-in support for this and more. Unless you are desperate, of course.

Advertisements