Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Custom Alert
PictureXtra
Navegacion y colision 3d - 3d Collision Navigation
HighLighting text
cXtraRTF
Josh Chunick's Personal Site
Title Bar MIAW
Change the Pattern of a Shape Cast member
Milliseconds
Replace returns with PC line breaks
 

 

 

Behavior Sound pan, rate shift

Added on 2/19/2001

 

Compatibilities:
D8 Mac PC Script Shockwave

This item has not yet been rated

Author: AndyPurviance

Copy the code into a Movie type script. To play a sound just type: playSound("soundName", {optional property list values}). If you use this then give me credit, at least inside the code somewhere.

Download PC Source    Download Mac Source
on playSound whichSound, soundSettings
  -- plays puppetsounds, handles stereo panning, pitch changes, and more.
  -- copyright 2001, Andy Purviance
  -- andy@purviance.com
  
  -- whichSound (required), string member name, ex:"boomFx"
  -- soundSettings (optional), property list may contain any or all of the following...
  -- example: [#locH:200,#type:#FX,#rate:0]
  
  -- #channel: integer sound channel (1-8), ex:2
  -- #type: symbol, ex:#VO or #FX, (ignored if #channel value given)
  -- #Priority: TRUE or FALSE, cut off any playing sounds if needed
  -- #pan: integer (-100 to 100), ex:-50, 0 is centerd
  -- #locH: integer spriteNum, ex:12, (ignored if #Pan value given)
  -- #rate: integer, ex:-3, <0 = higher pitch, >0 = lower pitch
  
  -- Example:
  -- playSound("help", [#type:#VO,#Priority:TRUE,#locH:sprite(2).locH])
  
  -- This example would trigger the sound "help" and stop any other sounds playing
  -- with #type:#VO (voiceover). #LocH means that if sprite 2 is on the left
  -- side of the stage then the sound would play mostly in the left speaker.
  
  if voidP(whichSound) then EXIT -- requires an sound name
  
  -- set defaults
  if voidP(soundSettings) OR not ilk(soundSettings, #proplist) then soundSettings = [:]
  if soundSettings.findPos(#Priority) = VOID then addProp soundSettings, #Priority, FALSE
  
  -- set sound channel
  if soundSettings.findPos(#Channel) = VOID then
    addProp soundSettings, #Channel, 3 -- default channel
    if soundSettings.findPos(#Type) <> VOID then
      voChan1 = 2
      voChan2 = voChan1+1
      fxChan1 = voChan1+2
      fxChan2 = voChan1+3
      fxChan3 = voChan1+4
      case soundSettings.type of
        #VO:
          if not soundBusy(voChan1) then soundSettings.channel = voChan1
          else if not soundBusy(voChan2) then soundSettings.channel = voChan2
          else if soundSettings.priority then soundSettings.channel = voChan2
          else EXIT
        #FX:
          if      not soundBusy(fxChan1) then soundSettings.channel = fxChan1
          else if not soundBusy(fxChan2) then soundSettings.channel = fxChan2
          else if not soundBusy(fxChan3) then soundSettings.channel = fxChan3
          else if soundSettings.priority then soundSettings.channel = fxChan1
          else EXIT
      end case
    end if
  end if
  
  -- set stereo pan
  if soundSettings.findPos(#Pan) = VOID then
    addProp soundSettings, #pan, 0 -- default pan centered
    if soundSettings.findPos(#LocH) <> VOID then
      case 1 of
        1: -- pan based on location within STAGE
          totalWidth = the stage.rect.width
        2: -- pan based on location within MONITOR
          totalWidth = the deskTopRectList[1].width
          soundSettings.locH = (the stage.rect.left) + soundSettings.locH
      end case
      soundSettings.pan = ((200*soundSettings.locH)/totalWidth)-100
    end if
  end if
  
  -- set rate
  if soundSettings.findPos(#Rate) = VOID then
    addProp soundSettings, #Rate, 0 -- default rate normal
  end if
  
  sound(soundSettings.channel).pan = soundSettings.pan
  sound(soundSettings.channel).play([#member: member(whichSound), #rateShift:soundSettings.rate])
end
------

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail