[Openal] Positive Gain on Listener

Chris Robinson chris.kcat at gmail.com
Mon Jul 9 15:25:32 PDT 2007


On Monday 09 July 2007 02:35:44 pm Paul Wilkinson wrote:
> If I mix all of my sounds through a single OpenAL source, will this be
> quieter than playing each sound through a different source?

Not implicitly, but it depends on how you do mixing. Normal (signed) mixing 
just adds up the sources, clamps, then writes to the final buffer. Like so:

for(samples_to_mix)
{
   int tempval = 0;
   for(sources_to_mix)
       tempval += srcs[source][sample];
   mixedbuffer[sample] = clamp(-32768, tempval, 32767);
}

Of course that's assuming all your data is 16-bit signed with matching 
frequencies (sources and the mixed buffer). It shouldn't be difficult to set 
that up, though.

Playing through different sources, though, does leave open the possibility for 
hardware mixing (given hardware drivers).

> Presumably the 
> volume needs to be scaled down in order to allow multiple sounds without
> clipping - how is the volume scaled? By a fixed factor?

As I see it, volume normalization isn't very trivial to do. I think what you'd 
have to do is watch the mixed sample peaks (both positive and negative) and 
scale the mixed output over time so that the output stays within range. 
You'll still get overflows though when the mixed samples become louder, since 
it takes a bit of time for normalization to react (react too fast and you'll 
get clicks and pops as the sample scaling jumps around). Also you'll still 
need to do floating point, 16.16 fixed point, or 8.24 fixed point mixing to 
be able to watch and clamp overflows.

This also has the side effect of making quiet samples louder and loud samples 
quieter, which generally isn't a good thing.


More information about the Openal mailing list