SoundData

Kind of class:public class
Package:com.nikrowell.media
Inherits from:none
Author:Nik Rowell
Classpath:com.nikrowell.media.SoundData
File last modified:Monday, 31 March 2008, 13:16:35
The SoundData class facilitates interactions with the SoundMixer class,
primarily, the SoundMixer.computeSpectrum() static method. It also
provides simple start, stop, toggle, and reset methods and allows
control over looping, volume and panning of a streaming sound.

The class is intended for use with audio visualization experiments.
See also:
  • flash.media.Sound
  • flash.media.SoundMixer
  • flash.media.SoundTransform
  • flash.media.SoundChannel

Summary


Constructor
  • SoundData (soundURL, looped:Boolean = false, volume:Number = 1)
    • Constructor, creates a new SoundData instance.
Constants
Instance properties
  • isPlaying : Boolean
    • Property[read-only], returns true if the sound is currently playing.
  • volume : Number
  • pan : Number
Instance methods
  • startSound : void
    • Method, starts the sound passed to the constructor (soundURL).
  • stopSound : void
    • Method, stops the currently playing sound.
  • reset : void
    • Method, stops the currently playing sound and resets its position to the beginning
  • toggle : void
    • Method, stops or starts the sound, based on the value of isPlaying.
  • compute (FFTMode:Boolean = false, stretchFactor:int = 0) : void
    • Method, takes a snapshot of the current sound wave.
  • read (multiplier:Number = 1, offset:Number = 0) : Number
    • Method, reads the data from the private property _bytes:ByteArray, into which SoundData.compute() writes

Constructor

SoundData

public function SoundData (
soundURL, looped:Boolean = false, volume:Number = 1)

Constructor, creates a new SoundData instance.
Parameters:
soundURL:
The URL that points to an external MP3 file.
looped :
(Optional, default = false) Boolean value indicating whether the should should loop. If set to true the sound restarts when Event.SOUND_COMPLETE fires.
volume :
(Optional, default = 1) The starting volume level for the sound. This can be modified before or during playback by setting the SoundData.volume property.

Constants

CHANNEL_LENGTH

public static const CHANNEL_LENGTH:int = 256
(read)

Instance properties

isPlaying

public isPlaying:Boolean
(read)

Property[read-only], returns true if the sound is currently playing.
Returns:
  • Boolean

pan

public pan:Number
(read,write)

volume

public volume:Number
(read,write)

Instance methods

compute

public function compute (
FFTMode:Boolean = false, stretchFactor:int = 0) : void

Method, takes a snapshot of the current sound wave.
Parameters:
FFTMode :
(Optional, default = false) A Boolean value indicating whether a Fourier transformation is performed. Setting this parameter to true causes the method to return a frequency spectrum instead of the raw sound wave with low frequencies on the left and high on the right.
stretchFactor:
(Optional, default = 0) The resolution of the sound samples. If you set the stretchFactor value to 0, data is sampled at 44.1 KHz; with a value of 1, data is sampled at 22.05 KHz; with a value of 2, data is sampled 11.025 KHz; and so on.
See also:
  • flash.media.SoundMixer.computeSpectrum.()

read

public function read (
multiplier:Number = 1, offset:Number = 0) : Number

Method, reads the data from the private property _bytes:ByteArray, into which SoundData.compute() writes
Parameters:
multiplier:
(Optional, default = 1) Number to multiply the floating-point value by.
offset :
(Optional, default = 1) Number to add to the floating-point value.
Returns:
  • the floating-point value multiplied by the multipler, if any, and added to the offset, if any.

reset

public function reset (
) : void

Method, stops the currently playing sound and resets its position to the beginning

startSound

public function startSound (
) : void

Method, starts the sound passed to the constructor (soundURL).
See also:
  • flash.media.Sound.play.()

stopSound

public function stopSound (
) : void

Method, stops the currently playing sound. Maintains the sound's current position.
See also:
  • flash.media.SoundChannel.stop.()

toggle

public function toggle (
) : void

Method, stops or starts the sound, based on the value of isPlaying. Maintains the sound's current position.