Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!adobe!hawley From: hawley@adobe.COM (Steve Hawley) Newsgroups: comp.sys.mac.programmer Subject: Re: Simultaneously played digitized sounds Keywords: sound Message-ID: <3459@adobe.UUCP> Date: 2 Jul 90 16:43:32 GMT References: <1032@swan.ulowell.edu> Reply-To: hawley@adobe.UUCP (Steve Hawley) Organization: Adobe Systems Incorporated, Mountain View Lines: 52 In article <1032@swan.ulowell.edu> jkeegan@hawk.ulowell.edu (Jeff Keegan) writes: > >I am currently writing a game where simultaneous sounds will be necessary. >I've observed that Beyond Dark Castle and SoundEdit 2.0 (two programs that >I have seen do this) do not call DoSndCommand, and must be either using the >old StartSound commands or the actual sound driver itself. I need to know >basically where to start if I am going to have to use the old sound driver. >How is it done? How can I play two sounds that I have in some format >(for example without Snd-type headers, like SoundWave resources used to be). Also consider Studio Session and Super Studio Session which do 6 and 8 voices simultaneously. I had hopes of writing the ultimate video game for the Mac (I still do). I tried to attack this problem and hoped to solve it have a general library when I was done. I came pretty close, but gave up in frustration. The general idea is to do all the sound generation yourself. There is a 720 (?) byte (I think -forgive my faulty memory if I'm wrong) buffer that is used for sound generation. Every time the video scan has drawn a row, it blanks and an interrupt is generated. At this time, a byte is fetched from the buffer and thrown to the dogs of the DA converter. The buffer is emptied every vertical retrace interrupt. The only catch is that not all the bytes in the buffer are used - half of them (the even ones, I think) are used for the disk drive. Here's what I did: I wrote a vertical retrace task that would take requests to start sound on one of 4 channels (with options for what to do when that channel is being used) and play it at 11 kHz until completion or interruption. When it gets woken up by the VBL manager, it loads the sound buffer, does house keeping and requeues itself. This worked like a charm --but for only 1 voice. The problem came in handling multiplexing. Whatever technique I tried failed miserably (ie, it played but with lots of unacceptable distortion). Bummer deal! I tried averaging, I tried OR'ing I even tried scrubbing, but they all worked poorly. I knew it wasn't a time problem because I tried each "channel" running with 3 other "null" channels, and it was clean (ie, it still did the math for multiplexeing, but something that would be a NO-OP to the data. The real bad news: Even if this code DID work, it would probably only work on a Mac SE or earlier machine because of the strict hardware dependency (although it did make correct use of the correct sound buffer base address). And it was written in inline assembly for the most part. Good luck... Steve Hawley hawley@adobe.com -- "A blow on the head is... ...worth two in the bush." -Basil Fawlty