Articles Archive
Articles Search
Director Wiki

Creating a sound channel server for puppetSounds

August 29, 1999
by Pat McClellan

Dear Multimedia Handyman,

I'm working on a Mac using Director 6.0 I am currently trying to design a soundgame for an enhanced CD project, where rolling on sprites activates a particular sound cast member. The problem now is that if there are 6 sprites on the stage that will all play the same sound (castmember 20) this sound will only start playing if it isn't playing yet. Is it possible to have a sound playing 3 times at the same time? Should I convert the sounds to Quicktime movies?


Dear Bert,

Converting your sounds to Quicktime movies (audio only) is a useful tactic for exerting control over starting and continuing your sounds in the middle of the sound file. You can use movieTime and movieRate for those commands. You can also play the sounds back at half and double speed, or even backwards. However, I can't see how Quicktime helps for your situation. Instead, you need to get a firm grip on using puppetSound. (Check out the details in your Lingo Dictionary.)

Puppetsound is a very handy command -- so handy in fact, most developers I know rarely use the sound channels in the score. Puppetsound is much easier and gives you great control. Plus, instead of 2 sound channels, puppetSound gives you 8 channels to play with. And yes, you can play different instances of the same sound in each of the 8 channels if you want.

Basically, you call for the sounds to be played in Lingo. You need to specify which sound channel (1-8) and which sound member (by name). After receiving the command, the sound plays as soon as the playback head moves to the next frame (or loops in the same frame). If the play head is static, you need to follow the puppetSound command with an "updateStage command" -- but that's not usually necessary.

Here's a behavior which you can attach to each sprite. When you drop it on a sprite, it will give you these options:

It will allow you to select which sound plays for each sprite. It also will automatically find an available sound channel so that multiple instances of the same sound will playback simultaneously.

property pSound
on getPropertyDescriptionList me
  set pdlist to [:]
  addprop pdlist, #pSound, [#comment:"Which sound?",¬
    #format:#sound, #default:0]
  return pdlist
end getPropertyDescriptionList
on mouseEnter me
  -- find an available sound channel
  repeat with i = 1 to 8
    if NOT soundbusy(i) then 
      set whichChannel = i
      exit repeat
    end if
  end repeat
  if not voidP(whichChannel) then
    puppetSound whichChannel, pSound
  end if

As you can see, the puppetSound part of this behavior is a single line of code. Very easy. The rest of the mouseEnter handler focuses on finding the first available sound channel. For that, I use the soundBusy property, which tells whether there is a sound playing in channel i (where i is sequenced by a repeat loop, starting with 1 and incrementing through 8). As soon as it finds an available sound channel, it exits out of the repeat loop and assigns the sound member to play in that channel.

Note that using this method, if there are sounds playing in all 8 channels, then the variable whichChannel will not get a value assigned (it would be "Void".) So, before using the variable in the puppetSound command, I test to make sure it is not void (otherwise, we'd get an error message.)

Download a sample movie in Mac (132 K) or PC (183 K) format.

Good luck with your project.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2019, Director Online. Article content copyright by respective authors.