[comp.sys.mac.programmer] Strange volume behavior with dual sound play

moyer@brahms.udel.edu (Eric Moyer) (04/07/91)

   I'm writing a game in which I use two sepatate sound channels to
play simultaneous asyncronous sounds. Oddly enough, whenever two sounds
are playing at the same time, the volume drops considerably. Then, when
one of the sounds terminates, the volume goes back up to normal for the
duration of the remaining sound, until two sounds 'collide' again.
   Has anyone experienced similar behavior, or does anyone have a clue as
to what might be causing it?

      Eric P. Moyer          /----- You are a fluke of the universe. ---------/
  moyer@brahms.udel.edu     /         You have no right to be here.          /
   Into the night as....   /        Whether you can hear it or not,         /
  KA3YED on 28.460 MHz    /--- The universe is laughing behind your back. -/

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (04/09/91)

I think this is a feature, not a bug.

Consider: when you have a single sound playing, it can be given the
full dynamic range that the Mac sound output hardware can handle (subject,
of course, to your volume setting). When you play two sounds simultaneously,
you have the possibility of the sum of the two sounds exceeding the maximum
representable value at some point (integer overflow). What do you do then?
By analogy with hardware, you should clip to the maximum value (which will
cause distortion, but not as bad as if you simply ignore the overflow). Maybe
Apple felt that this would be too complicated (and too slow) to implement,
so to forestall the problem, they halve the amplitudes of the component
sounds before summing them. And when you play three sounds at once, the
amplitude of each is divided by one-third, and so on.

Opinions, anyone? Do you think Apple did the right thing?

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
Commodore-Amiga offers to license TrueTask(tm) technology to
Apple and Microsoft.