plietar/librespot

Idea/Proposal: Loudness normalization

Opened this issue · 11 comments

(I know this project is not really maintained anymore, but I wanted to document this in case if anyone is interested.)

The official Spotify clients have an option (enabled by default) to normalize volume, which adjust the volume of differently mastered songs to sound equally loud (see https://en.wikipedia.org/wiki/Audio_normalization). This is primarily important when playing playlists.

Some pre-computed compensation values are stored in the proprietary ogg header (as 32 LE floats, starting at offset 144). I have a branch which reads these values and applies the first (I don't yet know what the others are good for) if librespot is started with --enable-volume-normalization: https://github.com/herrernst/librespot/tree/volume-normalization The resulting level still different from the Spotify client though.

Are you really sure that Spotify applies compression? Do you have any references on that?

I just apply the replaygain factor, so it doesn't sound special, everything else (i.e. implementing a compressor/limiter) would be nontrivial

@herrernst, out of interest, how did you discover where to find the values? Any ideas what goodies lay between bytes 160 and 167?

@herrernst
I've been using this for a week now or so. And it is working quite well, this is a welcome addition.
But occasionaly I've encountered some strange sounds added, which aren't there when running with librespot without the replaygain factor...
one track i've encountered is:

https://open.spotify.com/track/0CQMJlkWMcpiqyplxaYPH9?si=-x6V8wzXQWW3SB3h2Teb5w

is it just me? or are you also hearing this?

@cortegedusage thanks for your report. That is indeed a problem, that song is very quiet, and will be boosted which probably results in clipping. I will take a look at it hopefully sometime ...

@cortegedusage I've added a commit on my branch which prevents clipping by reducing the volume if necessary.

@herrernst thanks unfortunately i don't have time to test right now. But it looks good