Fans of many different types of music are now beginning to develop a new appreciation for the visual component of the live concert. Sophisticated light shows, digital displays, and entertaining special effects such as pyrotechnics and smoke all combine to enhance the entertainment experience by taking it to a whole new level of sensory stimulation.
Much of today’s music is delivered to the listener using some type of digital device. For those of you who listen to your library of songs on a computer, it is likely that your software application supports sound visualization. Both iTunes and WinAmp, which are among the most popular applications available, have supported sound visualization for quite some time.
As Flash designers and developers, we’ve struggled for many years to find an easy way to extract the appropriate data from an audio stream and create a visually compelling experience for our viewers. Several classes, recently introduced in Actionscript 3.0, have simplified the process for us.
The SoundMixer class contains static properties and methods for global sound control in the SWF file. To create sound visualization, the method we should focus on is called computeSpectrum. This method takes a snapshot of the current sound wave and places it into a ByteArray object. The values are formatted as normalized floating-point values, in the range -1.0 to 1.0. This provides us with numerical values which we can use to manipulate the position, scale, color, or even the intensity of a filter… the possibilities are endless.
The method described above takes the data in the ByteArray and uses it to draw a series of line segments. The data is updated continuously using the EnterFrame event handler, and since the spectrum is overwritten each time, we can use it update the visual.
Hopefully the demo attached below will jump start your process for making your own sound visualizations. Feel free to post your examples below!