I wanted to know what kind of values Audio Units expects in the buffer. Right now when I calculate the samples for a sine wave on one single frequency with amplitude 0.5 everything works fine.
But when I want to play several frequencies at the same time, for example 5 at once and I mix the samples together by summing them up the sample values get higher and the sound isn’t clean anymore.
So I want to know what my maximum sample value can be before I start getting a dirty sound.
On OS X
Sample values are typically within
[-1.0...1.0), where the maximum and minimum correspond to 0 dBFS. However, you should be prepared to handle larger sample values.Many people who work with floating point rendering/mixing graphs are accustomed to working without consideration of exceeding 0 dBFS. They may verify the signal does not exceed 0 dBFS only when they output to hardware or an audio file.
If you just have a synth which sums 5 sines, each at -6 dBFS, there should be no clipping of the signal under normal situations, even if you exceed [-1…1) because you are using floating point numbers to represent your signal.
there are a few exceptions to this:
I will typically prove/disprove this by sending it a signal which would obviously clip. Of course, a signal processor/generator which opted to process using ints could (and should) leave a good amount of headroom to avoid clipping (because it’s not likely that the processor processes audio using anything less than 32 bit).
On iOS
Because floating point processing is much slower on iOS devices, the canonic
AudioUnitSampleTypeis specified as Q7.24 fixed point.An explanation of this format can be found here. See also the posts surrounding this topic.
Because this is not floating point, you will have to much more careful about your gain stages to avoid internal clipping.
Also note that it is possible to configure a 32 bit
floatgraph on iOS. In that case, you should avoid exceeding[-1.0...1.0)at the output of your processor because it is likely that your output will be converted to a non-floating point representation sooner than later (compared to OS X), unless of course you have direct control of the gain staging at suitable points downstream in the processing chain and you adjust the amplitude at those points appropriately.