Playing Sound from Lingo

 

sound(channelNum).play()

 

sound(channelNum).play(member (whichMember))

 

sound(channelNum).play([#member: member(whichmember), {#startTime: milliseconds, #endTime: milliseconds, #loopStartTime: milliseconds, #loopEndTime: milliseconds, #loopCount: numberOfLoops, #preloadTime: milliseconds, #rateshift: shiftAmount}])

 

There are 8 channels you can use from Lingo, as opposed to the 2 in the score.  The play () function has 3 different versions.  The first version is for use with the queue() function (see below).

 

Basic playing:

 

sound(1).play (member "sound 1")

sound(2).play (member "wind")

sound(3).play (member "traffic")

 

Stopping:

 

sound(1).stop ()

 

Pausing:

 

sound(1).pause()

 

 

There can be only one sound playing in a channel at a time.

 

Each channel can actually play a stereo sound, not just mono.

 

To loop sounds, set the loop property for the cast member - or use the 3rd version of the play command with the property list.

 

sound(channelNum).play([#member: member(whichmember), {#startTime: milliseconds, #endTime: milliseconds, #loopStartTime: milliseconds, #loopEndTime: milliseconds, #loopCount: numberOfLoops, #preloadTime: milliseconds, #rateshift: shiftAmount}])

 

Properties:

 

#member           the member to play

#startTime        the beginning point to play from, in milliseconds

#endTime          end point, in milliseconds

#loopStartTime    point to start looping at

#loopEndTime      point to stop looping at

#loopCount        number of loops to play.  1 means just play once.

                  0 means loop forever.

#preloadTime      amount to preload before playing

#rateshift        pitch change. 0 is normal, 1 is up one half-step, 2 is                   up one whole-step, -1 is down one half-step, -12 is

                  down one octave, etc.

 

These are put in a property list so you can use just the ones you need:

 

sound(1).play ([#member: member "crickets",#loopCount:0]

sound(2).play ([#member: member "gamelan",#rateshift: 5]

sound(1).play([#member:member "eva",#loopstarttime:0,#loopendtime:4660,#loopcount:2])

 

The last example loops the first 4.66 seconds two times, then continues on to play the rest of the sound.  To set up a loop like this, just write down the times you want to use in SoundEdit.  Or, you create a cue point in SoundEdit and read it from lingo:

 

looptime = member("eva").cuePointTimes[1]

sound(1).play([#member:member "eva,#loopendtime:looptime,#loopcount:2])


Setting Volume

 

sound(channelI).volume = volume

 

volume goes from 0 (silent) to 255 (max).

 

sound(1).volume = 0

sound(2).volume = 255

sound(3).volume = sprite(1).loch

sound(4).volume = random(255)

 

Panning

 

Pan values go from -100 (left) to 100 (right)

 

sound(1).pan = -100

sound(1).pan = 100

sound(1).pan = sprite(2).loch + 160  -- center = 160

 

Constraining sprites in other sprites:

 

sprite(2).constraint = 1  -- constrains sprite 2 inside sprite 1

 

this is useful for making sliders - make sprite 1 be the width you need, and 1 pixel high.  Sprite 2 is the slider sprite.  Then:

 

sound(1).volume = sprite(2).loch

sound(1).volume = sprite(2).loch - sprite(1).left

 

 

--simple play

on mousedown

  sound(1).play(member "surf")

end

 

-- stop

on mousedown

  sound(1).stop()

end

 

-- pause

on mousedown

  sound(1).pause()

end

 

-- loop beginning infinitely

on mousedown

  sound(1).play([#member:member "eva,loopendtime:4660,#loopcount:0])

end

-- break out of loop

on mousedown

  sound(1).breakloop()

end

 

-- pitch shift one octave

on mousedown

  sound(2).play([#member:member("gamelan"),#rateshift:-12])

end

 

-- random segment

on mousedown

  d=member("surf").duration

  a = random(d)

  b = random(d)

  sound(1).play([#member:member("surf"),#startTime:a,#endTime:b])

end

 

-- volume control: put on sprite 2, make it moveable

-- make sprite 1 be 256x1 pixels

on mousewithin

  sprite(2).constraint = 1

  sound(1).volume = sprite(2).loch - sprite(1).left

end

 

-- random sound from list

on mousedown

  soundlist = ["chimes","gamelan","wind"]

  r=random(soundlist.count)

  thesound = soundlist[r]

  sound(1).play (member thesound)

end

 

-- keyboard handler

on keydown

  -- use the  'case of' structure to check key values

  case key() of

    "a": sound(1).play ([#member:member "gamelan",#rateshift:-4])  

    "s": sound(1).play ([#member:member "gamelan",#rateshift:0])  

    "d": sound(1).play ([#member:member "gamelan",#rateshift:4])  

    " ": -- check if sound is already playing.  if not, play it!

      if ( not sound(2).isBusy() ) then

        sound(2).play ([#member:member "surf"])

      end if 

  end case 

end

 

on keyup

  -- just use if/then here, because there's just one value i care about

  if key() = " " then

    sound(2).stop()   -- stop sound 2 when you release the spacebar

  end if

end