[comp.sys.mac.programmer] Overlapping SOUNDS

milo@ndmath.UUCP (Greg Corson) (08/02/89)

I have a game I'm working on which needs the ability to play overlapping
sounds from sound resources.  My problem is I can't seem to figure out a
clean way to do this that doesn't eat a lot of time.

What I need is the ability to play two or more "snd " resources, overlapped.
For example, playing background music, with occasional sound effects
dropped on top of it.

I suppose, what I need to do is read in the snd resources, extract the
samples and then add them together and feed them on-the-fly to the sound
manager.  It seems, however, that I would need to break up the sounds into
small pieces though...so I wouldn't have to wait for the current sound to
finish before inserting a new one.

I want to be able to have the background sounds playing, and be able to almost
immediately drop in a "gun" or "warning" sound at any time, without interrupting
the music.

If anybody has any great ideas (or sample code) on how to do this, please
write.  My biggest problem is that right now I don't have a lot of CPU time
to spair and, although I haven't tested it, I suspect if I start making 4 or
more calls a second to Sound_Do_Command I'm going to eat the machine.


Oh...also, Is it REALLY necessary to lock down a "snd " resource while it's
playing in the background?  The sound manager documentation doesn't mention
anything about this...but I think someone else here did at one time.


Greg Corson
19141 Summers Drive
South Bend, IN 46637
(219) 277-5306 
{pur-ee,rutgers,uunet}!iuvax!ndmath!milo
 

peirce@claris.com (Michael Peirce) (08/02/89)

>What I need is the ability to play two or more "snd " resources, overlapped.
>For example, playing background music, with occasional sound effects
>dropped on top of it.

If you have the time to wait you can wait around for system 7.  My 
understanding is that system 7 will add the ability to play at least
two SND resource concurrently.  (And maybe more than 2??? I don't recall).


Claris Corp. | Michael R. Peirce
-------------+--------------------------------------
             | 5201 Patrick Henry Drive MS-C4
             | Box 58168
             | Santa Clara, CA 95051-8168
             | (408) 987-7319
             | AppleLink: peirce1
             | Internet:  peirce@claris.com
             | uucp:      {ames,decwrl,apple,sun}!claris!peirce

lsr@Apple.COM (Larry Rosenstein) (08/02/89)

In article <1499@ndmath.UUCP> milo@ndmath.UUCP (Greg Corson) writes:
> Oh...also, Is it REALLY necessary to lock down a "snd " resource while 
it's
> playing in the background?  The sound manager documentation doesn't 
mention
> anything about this...but I think someone else here did at one time.

Yes.  The Sound Manager locks the handle for the duration of the SndPlay 
call, but if you are playing the sound asynchronously, then the SndPlay 
returns much sooner than the sound ends.  You should take a look at my 
Pascal unit, which is available in the Info-Mac archives.

Larry Rosenstein, Apple Computer, Inc.
Object Specialist

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1