plietar / librespot

Open Source Spotify client library
MIT License
1.13k stars 187 forks source link

Idea/Proposal: Loudness normalization #270

Open herrernst opened 6 years ago

herrernst commented 6 years ago

(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.

cortegedusage commented 6 years ago

hmm this sounds interesting,

although I'm not a programmer but merely an enthusiast. I'm wondering how you apply those value's because as far as I know (and can tell by listening) Spotify is not using any kind of gain reduction (replaygain) to get the volume straight but it uses compression to achieve this. So maybe this is why you don't get the results you want.

Btw. Is there any light on a new owner for librespot, because good things are happening now, shuffle, repeat, start volume. But not in one place, and it would be a shame because it's such a good piece of software.

anyways, we'll see.

2018-01-06 13:26 GMT+01:00 herrernst notifications@github.com:

(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 if librespot is started with --enable-volume-normalization (I don't yet know what the others are good for): https://github.com/herrernst/librespot/tree/volume-normalization The resulting level still different from the Spotify client though.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/plietar/librespot/issues/270, or mute the thread https://github.com/notifications/unsubscribe-auth/AV69TdCwrpHriTaHya3RIG-WC9Crqgvzks5tH2ZbgaJpZM4RVS5x .

herrernst commented 6 years ago

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

cortegedusage commented 6 years ago

Not on any spotify documentation, but here is what I came up with

http://productionadvice.co.uk/spotify-same-volume-setting/

hmmm and ofcourse I also find a post claiming the opposite...

https://community.spotify.com/t5/Social-Off-Topic/How-does-the-loudness-normalization-algorithm-work/td-p/1603671

but reading this:

https://community.spotify.com/t5/Live-Ideas/Desktop-Other-Improve-Spotify-s-volume-normalisation/idi-p/1128406

I come to think they might do both. So use replaygain to normalize the levels and compression to get a more radio like feel when listening so there is no audible difference when listening to the music.

anyway. these are my five cents.

2018-01-07 22:11 GMT+01:00 herrernst notifications@github.com:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/plietar/librespot/issues/270#issuecomment-355853037, or mute the thread https://github.com/notifications/unsubscribe-auth/AV69TV81CY98Xe6NHjZRtbE061dbtbO_ks5tITMdgaJpZM4RVS5x .

cortegedusage commented 6 years ago

remaining question is, how does your implementation sound like. because if it is actually replay gain factor you apply and there is no further compression, it might not be strange it sounds different from the native spotify client.

And this might be something I can imagine users would like to have (I would)

So is it actually doing what it should do? normalizing the volume?

and as I don't have a development setup would you mind sharing a binairy as I am very curious how it sounds?

thanks Dennis

2018-01-07 22:36 GMT+01:00 Dennis van Paassen dvpaassen@gmail.com:

Not on any spotify documentation, but here is what I came up with

http://productionadvice.co.uk/spotify-same-volume-setting/

hmmm and ofcourse I also find a post claiming the opposite...

https://community.spotify.com/t5/Social-Off-Topic/How-does- the-loudness-normalization-algorithm-work/td-p/1603671

but reading this:

https://community.spotify.com/t5/Live-Ideas/Desktop-Other- Improve-Spotify-s-volume-normalisation/idi-p/1128406

I come to think they might do both. So use replaygain to normalize the levels and compression to get a more radio like feel when listening so there is no audible difference when listening to the music.

anyway. these are my five cents.

2018-01-07 22:11 GMT+01:00 herrernst notifications@github.com:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/plietar/librespot/issues/270#issuecomment-355853037, or mute the thread https://github.com/notifications/unsubscribe-auth/AV69TV81CY98Xe6NHjZRtbE061dbtbO_ks5tITMdgaJpZM4RVS5x .

herrernst commented 6 years ago

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

kingosticks commented 6 years ago

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

herrernst commented 6 years ago

@kingosticks https://sourceforge.net/p/despotify/code/HEAD/tree/java/trunk/src/main/java/se/despotify/client/player/SpotifyOggHeader.java#l106

cortegedusage commented 6 years ago

@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?

herrernst commented 6 years ago

@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 ...

herrernst commented 6 years ago

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

cortegedusage commented 6 years ago

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