Reputation: 25265
I'm playing back a longish audio file (20 seconds or so) using AVAudioPlayer. I need to be able to pause and start in the middle of the file. When I pause or start while the audio is playing, there's a noticeable "pop" as the audio starts or finishes.
I've been able to improve the situation by doing a very fast fade-out (setting the volume multiple times using performSelector: withObject: afterDelay. But the sound is still a little glitchy with this technique.
Is there a standard way to start/pause AVAudioPlayer without these glitches?
Upvotes: 4
Views: 1130
Reputation: 70703
Use one of the lower level APIs (Audio Queues or RemoteIO). Smoothly ramp a multiplication factor from 1.0 to 0.0 over some number of PCM samples. Use that factor for the sample-by-sample gain factor in your own DSP audio mixer. Ramp from 0.0 to 1.0 on restart. Linear or an ease-in/ease-out half-cosine curve.
Upvotes: 0
Reputation:
Try sending the -prepareToPlay to your AVAudioPlayer object when it's paused. This will pre-load the sound.
If this doesn't work, try accelerating your fade-out by reducing the delay in the performSelector: withObject: afterDelay. Go crazy, milliseconds.
If this doesn't work too, try using a cleaner, higher-quality audio file (without irrelevant background noises)
If none of this works, please explain how the audio file in your app is being used in further detail.
Upvotes: 2