Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!ucsd!helios.ee.lbl.gov!pasteur!ic.Berkeley.EDU!eta From: eta@ic.Berkeley.EDU (Eric T. Anderson) Newsgroups: comp.sys.mac.programmer Subject: Re: Simultaneously played digitized sounds Keywords: divide Message-ID: <25974@pasteur.Berkeley.EDU> Date: 6 Jul 90 01:02:41 GMT References: <1032@swan.ulowell.edu> <36690003@hpindwa.HP.COM> Sender: news@pasteur.Berkeley.EDU Reply-To: eta@ic.Berkeley.EDU.UUCP (Eric T. Anderson) Organization: U.C. Berkeley EECS CAD Group Lines: 36 X-Local-Date: 5 Jul 90 18:02:41 PDT In article <36690003@hpindwa.HP.COM> krisl@hpindwa.HP.COM (Kris Livingston) writes: > >... The trick to avoid the >nasty distortion is to pre-divide the values in each of the waveforms by 4 >(the number of voices being combined). The advantage to this is that the >only processing your VBL task needs to do is addition. The disadvantage is >that the volume (loudness) of the overall sound is reduced. You could >experiment with dividing the waveform data by 2 (instead of 4) and then >check for overflow. (If sum > 255 then sum = 255). I know, it's crude, >but I've used it and it works--just don't plan on using the CPU for much >else while this is going on. :-) > Hey -- be careful. You know you're throwing away bits for no reason if you pre-divide. How about add first and then post-divide? On a Mac, doing byte-addition is just as quick as 16-bit addition (except if you're adding constants). Right? Why add to your distortion (especially for soft sounds where the lower bits make up for a lot of the sound level)? Let me point out another possibility that you might consider: You want four sounds to play, so you add them up. Map a log function onto the continuum of 1024 possible values you can get by adding. Map it linearly for low sound levels (so it approaches a ramp at small values) and slope it down for higher sound levels as you approach 1024. It seems to me that this might be a good idea and it only costs you a 1K-byte table. (add + lookup = cheap, right?) Yeah, okay -- I haven't tried this, I'm just speculating. Best Wishes -Eric Anderson eta@ic.berkeley.edu