I'm working on a custom HLS audio player for iOS.
Each .ts segment contains AAC audio. I extract AAC from each TS file, decode it to PCM (using FFmpegKit), and schedule it using AVAudioEngine.
❗ Problem:
Even though the segments belong to the same track, I hear click/pop sounds at the boundaries between segments.
I've tried:
- Trimming the first 2112 samples (AAC encoder delay)
- Using cross-correlation to align segment transitions
- Comparing waveforms: when I merge the TS files first and decode, the PCM waveform is smooth. But when decoding each TS independently, the result is discontinuous and causes audible artifacts.
✅ What worked:
CMSampleBuffer + AVSampleBufferAudioRenderer plays the segments perfectly without artifacts.
- ❌ But this path doesn’t allow me to modify the PCM data, which I need.
❌ Tried and failed:
- Tried attaching
MTAudioProcessingTap to AVPlayer, but when loading from an M3U8 playlist, AVAsset does not expose audio tracks, so I can't attach the tap.
❓ Question:
Is using AudioFileStream + AudioConverter the only way to preserve AAC stream continuity across segments and allow PCM-level processing?
If so, are there any working open source projects or sample implementations of this approach?
Any help or pointers would be greatly appreciated.