iOS audio clipping hazard!

The following code in juce_ios_audio.cpp

 for (UInt32 i = 0; i < numFrames; ++i)
                    for (int channel = 0; channel < channelData.outputs->numActiveChannels; ++channel)
                        *(outputShortData + channelData.outputs->activeChannelIndicies[channel]) = (short) (outputData[channel][i] * 32767.0f);

                    outputShortData += numChannels;

overflow on signals outside [-1…1] and give nasty artefacts.
Please use hard clipping instead.

1 Like

There is even no rounding…

If you use this in ROLI apps, there is a great opportunity to issue an update :slight_smile:

I don’t even understand with this process function stills “manually” does int/float and float/int conversions in the first place… CoreAudio contains highly optimized conversion code to do that.
The proper way to do all this iOS audio code would be to use an AudioUnit of kAudioUnitSubType_RemoteIO type, configure it to do duplex in a unique callback, configure it to directly get sample in float format and so on…

It’s been a long time since I’ve looked at this, but I seem to remember that using the ‘native’ stream format was required when accessing microphone input directly on iOS. I’m happy to be proven wrong though.

1 Like

Pretty sure microphone was added to RemoteIO graph in, like, iOS 3 or something. :slight_smile:

That being said, switching to that will create some interesting new problems. But that’s what we all pay @t0m for! GOOD LUCK, TOM!

1 Like
1 Like