13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with sound<br />

Left Channel Right Channel<br />

Left Channel Right Channel<br />

Values returned by the SoundMixer.computeSpectrum() method<br />

A. fftMode=true B. fftMode=false<br />

The computeSpectrum() method can also return data that has be<strong>en</strong> resampled at a lower bit rate. G<strong>en</strong>erally, this<br />

results in smoother waveform data or frequ<strong>en</strong>cy data at the exp<strong>en</strong>se of detail. The stretchFactor parameter controls<br />

the rate at which the computeSpectrum() method data is sampled. Wh<strong>en</strong> the stretchFactor parameter is set to 0,<br />

the default, the sound data is sampled at a rate of 44.1 kHz. The rate is halved at each successive value of the<br />

stretchFactor parameter, so a value of 1 specifies a rate of 22.05 kHz, a value of 2 specifies a rate of 11.025 kHz, and so<br />

on. The computeSpectrum() method still returns 256 bytes per stereo channel wh<strong>en</strong> a higher stretchFactor value<br />

is used.<br />

The SoundMixer.computeSpectrum() method has some limitations:<br />

Because sound data from a microphone or from RTMP streams do not pass through the global SoundMixer object,<br />

the SoundMixer.computeSpectrum() method will not return data from those sources.<br />

If one or more of the sounds being played come from sources outside the curr<strong>en</strong>t cont<strong>en</strong>t sandbox, security<br />

restrictions will cause the SoundMixer.computeSpectrum() method to throw an error. For more detail about the<br />

security limitations of the SoundMixer.computeSpectrum() method please see “Security considerations wh<strong>en</strong><br />

loading and playing sounds” on page 454and “Accessing loaded media as data” on page 1054.<br />

However, in an AIR application, cont<strong>en</strong>t in the application security sandbox (cont<strong>en</strong>t installed with the AIR<br />

application) are not restricted by these security limitations.<br />

Building a simple sound visualizer<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The following example uses the SoundMixer.computeSpectrum() method to show a chart of the sound waveform<br />

that animates with each frame:<br />

Last updated 6/6/2012<br />

A<br />

B<br />

458

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!