Papervision 3D Programing Tutorial - 3D Spectrum Analyser
66The SoundMixer.computeSpectrum function available in Flash allows developers to access the frequencies being played by the SWF file as a whole at any given point in time. This can be used to create a spectrum analyser, or a 3D one in our case with the addition of Papervision.
The computeSpectrum function takes a ByteArray as an argument, populating it with 512 float values: 256 for the left side and 256 for the right side. What is confusing about this though is that those 512 float values actually exist as 2048 byte values (4 bytes to 1 float). This means that to get the 2nd float value for the left hand side (assuming we have passed in a variabled called spectrum which is a ByteArray), you need to first need to call spectrum.position = 4, followed by a call to spectrum.readFloat(). Why 4? Because the first float takes up the first 4 bytes, those being at positions 0 - 3 inclusive. The second float starts at position 4, and the 3rd at position 8 etc. This is important because almost all of the sample code out there that reads the float values from the ByteArray do so with a series of calls to spectrum.readFloat() (which advances the position by 4 internally with every call). This sample creates a number of seperate objects that reference their own position in the spectrum ByteArray without any regard for the order that other objects have accessed it.
Anyway, once you get over the oddities of the ByteArray class creating a 3D spectrum analyser is actually pretty easy. The music I used in this sample was a free MP3 from a group called Tom Ugly.
Check out the demo here, and download the source here.
Find more Flash tutorials here.
|
Foundation ActionScript 3.0 for Flash and Flex (Foundations)
Price: $22.38
List Price: $39.99 |
|
Flash & Flex Stuff
Price: $0.99
List Price: $0.99 |
|
Foundation ActionScript 3.0 with Flash CS3 and Flex
Price: $14.61
List Price: $39.99 |
|
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
Price: $21.39
List Price: $39.99 |
PrintShare it! — Rate it: up down flag this hub
- More Papervision articles and tutorials
Check out even more Papervision tutorials here










Research Analyst says:
9 months ago
This 3D Spectrum analyzer is a cool way to add music frequency, cool stuff.