AudioStreaming icon indicating copy to clipboard operation
AudioStreaming copied to clipboard

[Help] Gapless Playback

Open BLeeEZ opened this issue 3 years ago • 9 comments

Hi, I am currently evaluating different audio libraries to add gapless playback to my Ampache/Subsonic App: Amperfy I integrated AudioStream and I am able to play songs with it. I am still noticing a small gap between songs. The engine is used with default configuration. The first song is played via player.play(url: url). 10 seconds before the currently playing song is finished I queue the next song via player.queue(url: url). Do I need to adjust/configure something get a true gapless playback?

BLeeEZ avatar Apr 25 '22 08:04 BLeeEZ

Hey, thanks for raising this, is there a demo server for Amperfy that I can use to try and investigate further?

dimitris-c avatar May 04 '22 14:05 dimitris-c

Thank you for your offered support. I have contacted you via your webpage so I can provide you login credentials for my demo server.

After you signed in with the Amperfy App you can navigate to playlist. There I prepared the Playlist call "Gapless". There are two songs in it "Phantom Part 1" and "Phantom Part 2". They were originally one song which I cut in two pieces. When the player view is open, you can tab on the icon in the upper left corner to show the currently queued songs for easier navigation.

BLeeEZ avatar May 05 '22 07:05 BLeeEZ

I recorded the output and as you can see in the screenshot there is a small but notable gap (18 ms).

Bildschirmfoto 2022-05-05 um 09 26 55

BLeeEZ avatar May 05 '22 07:05 BLeeEZ

After some investigation I'm not sure this can be improved... Although I added the mp3 files to the sample project and queued them and noticed a slightly less gap than your app.

I will have it as a TODO if I can come up with anything

And I do believe that mp3 encoding is somewhat non gapless, which I have converted the tracks to wav files and the was no gap audible.

Though there's another nasty bug that I found when seeking a wav file...

dimitris-c avatar May 11 '22 09:05 dimitris-c

Thank you for your time and afford.

BLeeEZ avatar May 11 '22 17:05 BLeeEZ

The default Music app in iOS will play mp3 files truly gapless, at least until this happened:

iOS 15.4 breaks 'gapless' playback in Apple Music

Maybe related?

Seems to be fixed in 15.5 betas, maybe the underlying framework is causing the gap in AudioStreaming too?

We need someone to test the beta.

bbsixzz avatar May 11 '22 19:05 bbsixzz

I don't think this is related to that bug After researching a bit there maybe a way to remove junk from mp3 files but that would require actually knowing when and if it's needed to remove that data... more info here https://en.wikipedia.org/wiki/Gapless_playback and technical info here https://lame.sourceforge.io/tech-FAQ.txt

dimitris-c avatar May 11 '22 19:05 dimitris-c

Alright, other than that all I can add is that iSub has working true gapless playback but it's a homegrown solution. So there must be a way to do it.

bbsixzz avatar May 11 '22 20:05 bbsixzz

iSub uses BASS player by unseen https://www.un4seen.com under the hood - so it's quite different than AudioStreaming approach, which uses AudioFileStream from Core Audio to play audio content.

I'm sure that BASS player uses their own decoding/encoding for supporting various audio types - since it's not open source is hard to tell their approach

dimitris-c avatar May 11 '22 20:05 dimitris-c

Closing this, mp3 are not gapless by default and should have extra handling to support this.

dimitris-c avatar Aug 31 '22 11:08 dimitris-c