[comp.sys.mac.programmer] Sound Manager and Loopback

hpoppe@bierstadt.ucar.edu (Herb Poppe) (01/03/90)

I have a Sound Manager problem:

I would like to write code that would play a sampled sound when I click
on a control. I want the "loopback" portion of the sampled sound to
play as long as the mouse button is down. When the mouse button is
released, I want any remainder of the loopback plus the portion
of the sound after the loopback to complete playing. If I then click
on the same or different control I want the same or different sound to play
in the same fashion. If I click on the same or different control while the
first sound is still playing, I don't want the second sound to start until
the first has completely finished, but I do want it to start without any
silence in between the sounds.

I have written code that accomplishes everything except for the condition
expressed in the last sentence. This is what I have done:

For each sound:
  I read the 'snd ' resource into memory.
  I move the handle high and lock the handle.
  I obtain a pointer to the sound header.
I open a sound channel, specifying the sampled synth.
When a control is clicked, TrackControl is called with an action
procedure that performs the following steps the first time (and only
the first time) it is called:
  SndDoCommand is called with a soundCmd to install the appropriate
  sound as an instrument in the channel.
  SndDoCommand is called with a freqCmd to play the sound for an
  indefinite duration.
When control returns after TrackControl, I call SndDoCommand with a
restCmd. This causes the sound to finish playing, PROVIDED no control
is clicked before the sound finishes.

If a control is clicked before the first sound has finished playing
then another soundCmd and freqCmd are queued to the channel. One of
three things will be heard depending on the value specified for the
duration of the previous restCmd:
  1) if the duration is less than the time it would take to
     completely finish playing the first sound, the first sound is truncated
     when the rest duration expires and the second sound starts to play.
  2) if the duration is greater than the time it would take to
     completely finish playing the first sound, then there is silence before
     the second sound starts to play.
  3) if the duration is equal to the time it would take to completely
     finish playing the first sound, then the first sound is not truncated
     nor does any silence occur before the second sound starts to play.

There appears to be no way to dynamically determine a duration for the
restCmd such that 3) above always holds. There appears to be no way to
determine when a sound has finished so as to hold off queueing the second
sound. Nor does there appear to be some other Sound Manager command
("finishCmd"), that I could replace restCmd with, that simply lets a
sound finish playing before the next sound command is dequeued from the
channel.

Is there a way to accomplish what I want with the existing Sound Manager?

If not, can/will a "finishCmd" be added to the next version of the Sound
Manager (the one to be released with System 7)?

Will the new Sound Manager be supported in new versions of System 6?
(Apple has said it will continue to support System 6 since it intends
to continue to sell one megabyte machines after System 7 is released).

Herb Poppe      NCAR                         INTERNET: hpoppe@ncar.ucar.edu
(303) 497-1296  P.O. Box 3000                   CSNET: hpoppe@ncar.CSNET
		Boulder, CO  80307               UUCP: hpoppe@ncar.UUCP