SoundControl

The SoundControl widget controls the volume of a specified sound based on the values from its inputSource. The sound is normally an .mp3 file that’s external to the Flash file in the same directory (but it is possible to play a sound that’s in the library of the Flash file – see the discussion below in the section Working with Library Sounds).

The sound will start if the input value rises above the number set in the threshold parameter, which by default is 500. The sound can be set to pause where it is, or reset to the beginning of the sound when input values falls below the threshold.

You can control the volume and pan of the sound by setting the inputSourceVolume and inputSourcePan parameters to inputs.

If you need finer control of when the sound plays, for example the sound comes on in a specific range of a sensor, use the Envelope widget in between the inputSource widget and SoundControl.

On Screen Features

  • vol – Indicates the value of the volume as read from the inputSourceVolume input. 0 is silent, 512 is “normal” volume, and 1023 is maximum volume. The default value of the SoundControl volume is set by the “volume” parameter.
  • pan – Indicates the value of the volume as read from the inputSourcePan input. 0 is left channel only, 512 center pan with same volume in both channels, and 1023 is right channel only. The default value of the SoundControl pan is set by the “pan” parameter.

Parameters

  • inputSource –  The instance name of the source the widget listens to, e.g AnalogIn or DigitalIn – this input determines if the sound plays or not, based on a comparison to the “threshold” parameter. Any input from inputSource that’s equal to or higher than the threshold causes the sound to play (depending on the soundBehavior parameter).
  • inputSourcePan – NEW – The instance name of the widget that sets the pan.
  • inputSourceVolume – NEW – The instance name of the widget that sets the volume. This is a significant CHANGE from previous versions of the SoundControl widget, which combined volume control and sound trigger. Now volume is controlled by this separate input, and is independent of the play threshold.
  • invisible –  If set to “true” or checked, the widget will disappear when the Flash movie is run – NOTE: you can make all the widgets invisible interactively when the Flash moving is running simply by pressing the backslash key “\”.
  • listItemName – If set to other than the default of “none”, SoundControl will request the next list item from the ListItems widget that’s named in this parameter, each time the audio is restarted. Requires that soundBehavior is set to one of the restart settings.
  • loopSound –  If set to “yes”, the sound loops forever
  • pan – NEW – Sets the default panning position of the sound. The default of 512 places the sound centered between left and right. 0 forces all the sound to the left channel. 1023 forces all the sound to the right channel. The pan position can be changed at run time based on input value from inputSourcePan.
  • soundBehavior – NEW  – This parameter sets the behavior of the widget.
    • continuous – the sound will start playing as soon as the swf is launched, even if the volume is off
    • pause – the sound will pause when the main input value falls below the “threshold” setting, and begin playing from the same location as when it paused when the value rises above the threshold.
    • restart – the sound will stop when the input value falls below the “threshold” setting, and start playing from the beginning of the sound when the value rises above the min setting.
    • restartPlayToEnd – the sound will start playing when the value rises above the “threshold” setting and the sound will play to the end regardless of the input value after that. Typically, with this setting loopSound should set off, otherwise the sound will play forever.
    • restartPlayToEndInterrupt – the sound will start playing when the value rises above the “threshold” setting and the sound will play to the end even if the input value falls below the threshold after that. If the input value falls below the threshold and then rises above the threshold, the sound will restart.
  • soundName – Depending on the setting of soundSource, this is either the filename of the .mp3 file in the same directory as the SWF, or the LINKAGE name of the any sound in the library. Note that if you leave this set to the default “defaultSound” or put in a sound name that does not exist, the SoundControl widget will play a default drum loop sound that’s contained in the widget – this helps if you haven’t yet created your sounds and need a sound to test with.
  • soundSource – This determines if the sound is loaded from the library in the Flash file or from a file on the disk.
  • threshold – For the soundBehavior pause and all the restart behaviors, the threshold determines at what input value the sound begins to play. Input values less than this number cause the sound to stop/pause, and values greater than or equal to this value cause the sound to start.
  • volume – NEW – Sets the default volume of the sound. The default of 512 is the standard Flash volume. 0 is silent and 1023 is twice the normal volume. The volume can be changed at run time based on input value from inputSourceVolume.

Code Interface

soundControlInstance.setVolume(value);

Change the volume, where value is between 0 (silent) and 1023 (twice the normal volume). A value of 512 is normal volume.

soundControlInstance.setPan(value);

Change the pan position, where value is between 0 (only left channel) and 1023 (only right channel). A value of 512 is sets the pan to the “center”, where the volume is the same in both channels.

soundControlInstance.triggerSoundProcess(value);

Trigger the play or stop of the sound, where value is compared to the setting in the threshold parameter. Values less than the threshold cause the sound to stop/pause, and values greater than or equal to this value cause the sound to start. If used with listItemName, and if the sound is started, a new sound file from the list will be used.

soundControlInstance.startSound(soundPosition, loops);

Starts the current sound at soundPosition (in milliseconds), and the number of loops.

Working with File based sounds

If you select “file” as the soundSource, this name is the sound filename in the directory where your flash file is. If you want to put your sound files in a sub-directory, you would enter something like “sounds/myfile.mp3”.

For most cases, it is much better to have your sounds on disk rather in than in the library of your .fla file. The .fla file will get very large and slow to open if you use library sounds.

ONLY .MP3 TYPE FILES ARE SUPPORTED FOR DISK AUDIO FILES — .WAV FILES WILL CRASH THE FLASH PLAYER

Working with Library based sounds

If you use “library” as the soundSource YOU MUST SET THE NAME FOR THE SOUND IN THE LIBRARY: To set this on the sound, control click on the sound in the library, and select LINGAGE… In the dialog that’s presented, check EXPORT FOR ACTIONSCRIPT and EXPORT IN FIRST FRAME. Then set the name you want to use (no spaces) in the IDENTIFIER box.

Library sounds are best when you need to synchronize multiple looping sounds. If you need precise sync, be sure to make and import your sound files into the the Flash library in aiff or wav format. Sounds imported as .mp3 files will have an indeterminate extra amount of silence at the end of the file and cause problems with synchronization.


Last modified December 27th, 2013