🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Clipping when app is started playing sound via speaker, no clipping when started with headphones plugged in

Started by
5 comments, last by plapps 4 years, 5 months ago

Hello

In the mobile phone game I'm working on, I've built a music-making sequencer of sorts. The way it works is that 5 separate audio tracks (3 instruments with notes and 2 'drummers') are being played simultaneously, 'going to' different notes at different moments, and this way I can program it to play any music I want.

The sound quality is great when I test export this app to Windows (the game is being made in GameMaker on Windows).

Running the app on iOS, the sound is also great, but... only with headphones plugged in. There's this 'click' sound at the beginning of each note when playing through the phone speaker.

To be more specific, what actually happens is that when I start the app with sound going via the speaker - this distortion occurs. Then when I plug in the headphones while the app is running, the distortion is still there. BUT if I start the app with headphones plugged in, it sounds correct, AND THEN when I pull out the headphones while the app is running it still sounds correct going through the speaker.

It almost seems like the sound is processed differently by iOS when the app is started 'in headphones mode' and different in 'speaker mode' - is that possible?

What's causing this and how can I remedy this?

I'm testing on an iPhone 6 btw.

Advertisement

The distortion is probably caused by clipping because your audio is too loud when mixed together. There is some kind of dynamic range limiting active when you test on windows which makes it sound OK by automatically turning down the volume when the audio is too loud. Windows WASAPI shared mode passes all audio through a limiter to prevent clipping when multiple apps play audio simultaneously. This feature may not be active on the actual test device, and may be turned on/off depending on output transducer (headphones vs. speakers). The phone is probably trying to protect users' hearing by applying limiter in headphone mode, but turning it off in speaker mode where this is less of a concern.

To fix this, you can either turn down the level of all sounds your app generates so that you can ensure there is never any clipping, or you can apply limiting to the audio yourself by inserting a limiter right before the final output.

@Aressera Thanks for your reply Aressera! I'm going to try turning everything down and see what happens. It seemed to me like the phone has a different ‘processing mode’ for audio when using headphones vs speaker, and when plugging the headphones in or out ‘mid-play’ it stays in that mode - that's why the clipping continues when starting with speaker and switching to headphones, and vice versa. I was thinking that it is simply dedicating 'more juice’ to audio when in headphones mode, when better quality of sound is needed, but what you said about the limiter makes sense.

…so there is hope after all lol

@Aressera Hey, I wonder if you have any other ideas as to what might be happening, because I'm not sure this is it.

I experimented with turning down the volume, including an extreme scenario where each component of the mix is at 10% (in the original mix most tracks are at 100% volume, one at 70% and one at 50%). So much quieter.

But there is no difference - the weird ‘click’ sound is still there. BTW, it doesn't sound like loudness distortion - but a ‘click’ sound at the beginning of each sample played.

The way my app works is that I have audio files with all notes recorded one by one and the app is continuously playing them and jumping around at given moments to specified note positions. There are 3 tracks like this and 2 drum tracks that just have 1 sample at the beginning.

The bass drum instrument, which is the most bassy, has the loudest ‘click’ but whether at 100% or 10% volume, there click is the same…

All these problems are not present if I start the app with headphones plugged in (iPhone 6), and after unplugging them while the app is running, the sound stays correct playing via the speaker.

Maybe there's some way to force the iPhone to always process the sound as if the headphones were plugged in?

I appreciate your help!

Since you mention jumping around, make sure you start and end samples from a zero-point (i.e. where the waveform crosses the x-axis). Otherwise you get a sudden jump in amplitude which can produce such audible clicks.

Not sure if this is your problem but it is something to keep in mind.

@Prototype This was an issue in the early version of this system. I solved it by doubling each track, with one of them being muted, and the jump is actually a cross-fade to the other track. This solution removed all crackling/distortion and made the whole thing actually enjoyable to listen to. ?

This topic is closed to new replies.

Advertisement