Please see this update
As far as I know the company formerly known as Macromedia did not add any kind of dynamic sound generation methods to ActionSciprt3 / Flash 8.5. However, they did add two features we can use to hack it:
- ‘ByteArray’ class which is a low level data class
- ‘Loader’ class (formerly MovieClipLoader) can load from a ByteArray, as well as the normal loading from a URL.
So the theory is, I generate valid swf into a byteArray that simply contains sound data, then I load that and it plays.
This would involve me understanding the swf binary file format…however that’s a bit of a pain, so I cheated.
- Create a .fla in Flash 8 & import a sound into frame 1
- Copy & paste the entire data from the .swf into an array in my AS3 project
- At runtime, replace the central part of the array with new data (leaving the header and footer of the data intact). Just a bit of trial & error to see how much data needs to be left
Here is a very simple example:
Type a frequency into the text box at the left, then click on the red box on the right. You should here a 1 second tone being generated.
It’s still not perfect, there seems to be a bit of distortion, but it gets the idea across. For reference, the format of the sound seems to be 16 bit signed samples. The sample rate is based on the swf header, and the one I am using is set at 11khz I believe…