Sound - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Sound

Description:

Flash ActionScript 3.0 Sound Thomas L vgren, Flash developer thomas.lovgren_at_humlab.umu.se Introduction to Sound Lecture Outline In this lecture we ll discuss and ... – PowerPoint PPT presentation

Number of Views:177
Avg rating:3.0/5.0
Slides: 15
Provided by: Thomas1344
Category:
Tags: design | sound

less

Transcript and Presenter's Notes

Title: Sound


1
Sound
Introduction to
Flash ActionScript 3.0
Thomas Lövgren, Flash developer thomas.lovgren_at_hum
lab.umu.se
2
Introduction to Sound
Sound
  • Lecture Outline
  • In this lecture well discuss and practice the
    following topics
  • AS3 Sound Architecture
  • Loading and playing External and Internal sound
  • Sound related classes
  • Coding a basic Sound Player
  • More sound functions features
  • Microphone
  • Sound Visualization

3
AS3 Sound Architecture
Sound
  • In AS3 there are a lot of useful classes and
    methods for different kinds of sound
    functionality
  • Sound class Is used to load, play and manage
    basic sound properties
  • SoundChannel class Is used to create a separate
    channel for each new sound played (channel does
    not refer to left or right channel of stereo)
  • SoundMixer class Creates a central mixer object
    through which all sound channels are mixed
  • SoundTransform class Is used to control the
    volume, and panning between left and right stereo
    channels of a source
  • Microphone class Lets us control the gain,
    sampling rate and other properties of a
    Microphone

4
Internal and External Sound
Sound
  • In Flash there are basically two different ways
    of working with sound
  • Internal (sound in library) and External Sound
    (loading a sound)
  • Its recommended that we use external sounds - by
    loading a sound into the application, we can keep
    the file size down
  • Examples of how to use the different types
  • External sound Load a sound file (MP3) into the
    application. This could be for example
    background music, mp3 player etc.
  • Internal sound Attach sound from Library
    (linkage). Small sounds (file size), for example
    sound effects for a game, button click-sounds
    etc.

5
Sound class (1/2)
Sound
  • The Sound class is used to load, play and manage
    basic sound functionalities
  • Some useful properties, methods events for the
    Sound class
  • Sound(), load(), play(), complete, bytesLoaded,
    bytesTotal, length etc
  • //create a new sound object
  • var my_soundSound new Sound()

6
Sound class (2/2)(Load play External Sound)
Sound
  • Here is an example of how to load and play an
    external MP3 sound, and play it by using the
    Sound class
  • var my_soundSound new Sound() //create a new
    sound object
  • my_sound.load(new URLRequest("David Gray - Sail
    Away.mp3")) //load
  • my_sound.play() //play sound
  • Note! Its recommended that we also uses
    Events/functions to check if the
  • loading is complete

7
SoundChannel
Sound
  • The SoundChannel class, can be used to create a
    separate channel for each new sound played, stop
    a sound and/or get sound-peaks
  • An application can have multiple sound channels
    that are mixed together
  • Some useful properties, methods events for this
    class
  • Stop(), soundComplete, leftPeak, rightPeak,
    position etc
  • var my_soundSound new Sound() //create sound
    object
  • var my_channelSoundChannel new SoundChannel()
    //create channel
  • my_sound.load(new URLRequest("David Gray - Sail
    Away.mp3")) //load
  • my_channel my_sound.play() //play sound
    through channel

8
Internal Sound(Sound in library/attach a sound)
Sound
  • For playing a sound from library first we need
    to import the sound to Flash, then set up the
    Linkage property
  • in library
  • 1. Right-click on the sound in library
  • 2. Select Linkage (Properties in CS4)
  • 3. Check the box Export for ActionScript
  • //create a new "library" sound channel object
  • var library_soundexplode_sound new
    explode_sound() //sound object
  • var explode_channelSoundChannel //create
    channel object
  • explode_channel library_sound.play() //play
    sound through channel

9
SoundTransform class
Sound
  • The SoundTransform class, allows us to adjust the
    sound volume, and/or panning between left and
    right channel of a source
  • Some of the properties and methods for this
    class
  • SoundTransform(), pan, volume etc
  • //function that adjust the volume by dragging a
    slider
  • function adjustVolume(eventEvent)void
  • var volNumber volume_mc.slider_mc.x / 100
  • var stSoundTransform new SoundTransform(vol)

10
SoundMixer class
Sound
  • The SoundMixer class creates a central mixer,
    changes to the mixer will affect all sounds
  • Some of the properties and methods for this
    class
  • stopAll(), computeSpectrum(), bufferTime etc
  • //function that stops all sounds
  • function stopAllSound(eventMouseEvent)void
  • SoundMixer.stopAll()

11
Stop, pause play sound
Sound
  • There are a couple of more interesting sound
    features, for example if we want to stop, pause
    and play a sound we can write like
  • //declare variable, get the sound position
  • var pausePosNumber sound_channel.position
  • sound_channel.stop()
  • ...and at a later point we can start the sound at
    that position by writing
  • sound_channel my_sound.play(pausePos)

12
Sound Complete
Sound
  • If we want a sound to repeat when finished, we
    can add a listener to the Sound/channel object
    with the event SOUND_COMPLETE
  • //add listener to the sound through the channel
    object, call method
  • my_channel.addEventListener(Event.SOUND_COMPLETE,
    soundComplete)
  • //handler/function for repeating the sound
  • function soundComplete(eventEvent)void
  • my_channel my_sound.play() //play sound again

13
Microphone
Sound
  • The Microphone class allows us to connect a
    microphone to Flash
  • By using the activityLevel method, its possible
    to for example animate the activity directly
    from the microphone
  • var my_micMicrophone Microphone.getMicrophone()
  • Security.showSettings(SecurityPanel.MICROPHONE)
  • my_mic.setLoopBack(true)
  • my_mic.setUseEchoSuppression(true)
  • stage.addEventListener(Event.ENTER_FRAME,
    onLoop)
  • function onLoop(eventEvent)
  • line_mc.width my_mic.activityLevel 5
  • activity_dyn.text "Activity "
    String(my_mic.activityLevel) ""
  • width_dyn.text "Line_mc Width "
    String(line_mc.width) "px"
  • trace(my_mic.activityLevel)

14
Sound visualization
Sound
  • By using the SoundMixer class and the
    computeSpectrum method, we can create interesting
    and fancy animations synchronized with the sound
    source
Write a Comment
User Comments (0)
About PowerShow.com