create your own

Papervision 3D Programing Tutorial - 3D Spectrum Analyser

66
rate or flag this page

By phyxx


The 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.


Comments

RSS for comments on this Hub

Research Analyst profile image

Research Analyst  says:
9 months ago

This 3D Spectrum analyzer is a cool way to add music frequency, cool stuff.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working