Re: Peak limiter on iPhone needed to mix two .wav files
Re: Peak limiter on iPhone needed to mix two .wav files
- Subject: Re: Peak limiter on iPhone needed to mix two .wav files
- From: Brian Willoughby <email@hidden>
- Date: Thu, 21 Jan 2010 12:00:26 -0800
On Jan 21, 2010, at 11:30, Mo DeJong wrote:
I am looking for a way to mix two .wav files on the iPhone and then
play the result using an AVAudioPlayer or with CoreAudio at the C
level. I have code that reads .wav files, mixes the PCM data, and then
plays the result on the iPhone. But I am having a problem with
clipping when the two audio files both contain a loud sound, when
these sounds overlap then the sum of the two PCM values will exceed
the 16 bit sample value rage and the audio will clip.
I am wondering if there is some kind of peak limiter available on the
iPhone? I read that on MacOSX there is a peak limiter AU plugin, is
there anything like it available on the iPhone, and if so how would
one use it with a audio mixing application? If not, could anyone
suggest an alternative that I might explore?
You have three options:
1) Reduce the volume by 6 dB so that clipping is impossible. This is
not popular because each audio file is quieter than it would be
alone. In assembly, you can stay at 16 bits and use the overflow or
carry bits as an input to a shift operation that handle the 6 dB
reduction after mixing the two. In C, you can use 32-bit variables
for mixing, then reduce, but this will probably take more CPU. In
either case, you may want to dither the results because of the
quantization.
2) Use saturation to clip instead of overflow. Many video game audio
engines use this approach, since the volume of each audio file
remains the same. Your existing code is probably wrapping the
waveform around from extreme positive to extreme negative, or the
converse. With saturation, you still have clipping, but it will
sound more "analog" - or at least less objectionable than wrap-around
overflow.
3) Write your own peak limiter code.
Brian Willoughby
Sound Consulting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden