regosen / Gapless-5

Gapless JavaScript audio player using HTML5 and WebAudio
MIT License
136 stars 22 forks source link

Automatically trim short silence from MP3 encoding? #55

Open ben-juodvalkis opened 6 months ago

ben-juodvalkis commented 6 months ago

Hello! Gapless5 is awesome! Thank you so much for building this. When I loop a WAV file, it indeed seems gapless. However, mp3 files are often created with a little bit of silence at the end, due to the nature of the encoding. Could you imagine implementing a feature to trim that last bit of silence, ensuring true gapless playback of music in MO3 format?

regosen commented 6 months ago

I'm glad you like it! Regarding encoding, the Gapless5 library doesn't read the audio itself to determine the format details (bitrate, etc.), so it's not able to make changes accordingly.

But you could set the crossfade in the options passed into the Gapless5 constructor. That's how other applications solve this problem using Gapless5. I've seen 25 ms used as the crossfade amount for 160bps MP3s, e.g. const player = new Gapless5({crossfade: 25}). By default, the player will overlap both tracks at full volume (which you can adjust, see crossfadeShape in the README)

ben-juodvalkis commented 6 months ago

Does the crossfade work when looping a single track, or should I load the same track twice, and have them alternate?

regosen commented 6 months ago

Ah, if you're looping a single track, Gapless5 lets the native WebAudio or HTML5 Audio handle looping internally (which does a perfect job of seamless looping from what I can tell). The crossfade amount should not affect it in that case.

ben-juodvalkis commented 6 months ago

Thank you! Because mp3 and Mac files are created with a small bit of silence at the beginning or end, I think I'll have to set it up as a two-song playlist, so I can get crossfading. For future reference, there are ways to trim these silences if they are encoded into the file's metadata: https://lame.sourceforge.io/tech-FAQ.txt Thanks again for the great work

ben-juodvalkis commented 6 months ago

Hey, I wrote you an email, but don't want to get caught in a spam-blocker, so I'm pasting it here:

My name is Ben Juodvalkis and I'm a professional musician/composer living in SF since 2007.

I've recklessly decided to make a music app, even though I have minimal coding experience.

Lurking on your github page, I notice that you're based in San Francisco too!

I have many ideas, and even more questions, and I wonder if you'd be interested in serving as a consultant or even as a contractor for my project? Or we could just grab a coffee and nerd out about music.

Thank so much, and Happy new year! Ben