HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: marcoxD95 on 2018-07-11 19:00:34

Title: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: marcoxD95 on 2018-07-11 19:00:34
I recently was interested in this whole ReplayGain thing because I was often annoyed by how different the volume on many tracks is and how I have to change the volume slider all the time...

I had no idea what exactly db is though and how ReplayGain fixes my volume. It also seems to address something called clipping and some loudness war thing. I honestly never heard of cared about this until now.

Usually my music is around 95-100db which seems to be normal nowadays. I scanned a track with MP3Gain to get its average db and it said it is 100. Now ReplayGain said it should be adjusted -13db in its tags. Which I guess would be somewhere around 89? I am not sure if it says this from the highest tone in the whole track or average. But as far as I see it, it usually should normalize music to 89db, right?

There is also the preamp setting in Foobar2000 for ReplayGain. When I change it to, lets say +5, it takes 94db as "normal"? Which means it should usually lower the volume by around 6db, if we take this 100db track as example, right?

Now there is also this volume slider inside the foobar2000 program. Which seems to lower or higher the volume. I guess at 0 it is putting out the default db value like 89db, right? Considering everything is on full volume. How exactly does the Windows volume slider play into this? Does foobar, or better, my headphones still give out 89db if my Windows slider is also on 100%?

Also clipping is when an audio sounds weird or compressed and might even cause damage to speakers, right? I never cared or knew what clipping is but some examples online seemed to actually give me a good example. There was even record examples where music from 1990 was played and then some remaster from 2000+ with high volume. Loudness war is the usual term for this. The older music seemed to have a lot more heights and sounded less "cropped".

Now if the artists or audio engineers master their music at the standard 95-100db nowadays, and I use ReplayGain to playback it at 89db, does this mean the audio sounds better or the loudness war problem is fixed? I am not sure here how this works. Isn't this stuff directly saved inside the audio data or does every music, no matter how it is mastered, clip at like 95+ db? Like this it would mean that pretty much every put out record nowadays gets actually hurt in its audio quality. I am just not sure if ReplayGain does fix this completely or only improve.

Sorry if those questions seem a bit much. I am just really interested into the whole topic and I am not 100% sure if I understood everything, beside of the fact that there are some questions left.

Thanks for any info you can help me with! :)
Title: Re: Did I actually understand how ReplayGain and db works in music? Questions!
Post by: DVDdoug on 2018-07-11 23:01:07
I can't answer all of your questions...

Quote
I had no idea what exactly db is though
Decibels are a relative, logarithmic, measure of amplitude (or power).   You always need to know the reference.  
 
Sorry...   This gets confusing and ReplayGain makes it even more confusing... 

dB SPL (sound pressure level) is the loudness of acoustic sound in the air.      The 0dB reference is approximately the threshold of human hearing so dB SPL is always a positive number.

The 89dB ReplayGain number refers to SPL, but it's not really SPL because it doesn't know how loud you've got the volume turned-up, etc.    It turns-out that because of the Equal Loudness Curves (https://en.wikipedia.org/wiki/Equal-loudness_contour) (a characteristic of human hearing) you have to choose a know-standard listening level if you want to match the volume of different recordings...    Song-A may be louder when listening quietly, and song-B may be louder when listening loudly.    If we choose a standard listening level (such as 89dB) we solve that problem.

The digital reference is 0dBFS (zero decibels full scale).   That's the "digital maximum" and it's "as high as you can count" with a given number of bits (8-bits, 16-bits, 24-bits).   The values are scaled so a 0dB 8-bit file is just as loud as a 24-bit 0dB file.  So, digital dB levels are usually negative    With floating-point you can go positive (over 0dB) and MP3s can go over 0dB.     But, your digital-to-analog converter (DAC) is integer based and it cannot go over 0dB.

With digital levels, we are usually dealing with peak dB levels.    The digital peak level does NOT correlate well with loudness.  A lot of quiet-sounding have "maximized" 0dB peaks.   These quiet-sounding songs cannot be turned-up without clipping so if you want to match loudness you have to turn-down the louder files.   

The RMS or average correlates better with perceived loudness, but the ReplayGain algorithm takes frequency content into account and it does a better job.   Audio compression and limiting can be used to bring-up the average level without hard-clipping the peaks.   It makes the sound "more dense" or "more intense" and less dynamic.   (That's how you "win" the loudness war!)

If you reduce the digital volume by -3dB, the peak and average will both go-down by -3dB, and the acoustic SPL level will also go-down by -3dB (assuming you don't touch the volume control).

Quote
It also seems to address something called clipping
Clipping (https://en.wikipedia.org/wiki/Clipping_(audio)) is distorted flat-topped waves.  You get digital clipping if you try to go-over 0dB (with integer formats).   DACs, ADCs, regular WAV files, and CDs are all hard-limited to 0dB.  

You can get analog clipping if you turn-up the volume and you try to get 110 Watts out of a 100W amplifier.

Clipping is a (nasty) kind of dynamic compression.    If you're clipping and you turn-up the volume, the average level goes-up and it gets louder but the peaks can't go up.     

...Back to ReplayGain - If you set the ReplayGain target volume higher, two things can happen - If you allow clipping the quiet songs will get louder but may songs may get clipped.    If you don't allow clipping ReplayGain won't turn-up the volume on many songs so you might think ReplayGain isn't doing anything (and it's not doing much).  

A lower target volume gives ReplayGain "more room to work".  The 89dB level is a compromise and works with most songs.  Some people don't like their songs so quiet, but if you've got enough analog gain & power you can still crank-up the analog volume and get 100W out of that 100W amplifier and rattle the walls and annoy your neighbors!


Quote
my headphones still give out 89db if my Windows slider is also on 100%?
No...  Your headphones, DAC, and headphone amplifier are not calibrated.   The SPL level is unknown.   Your headphones/speakers may be louder or quieter then mine, or I might have the analog volume control turned-up, etc.   Movie theaters are calibrated (so a certain digital level gives a certain SPL level) but virtually nothing else is.   And even in the movie theater it depends on where you are sitting.

Quote
Now if the artists or audio engineers master their music at the standard 95-100db nowadays, and I use ReplayGain to playback it at 89db, does this mean the audio sounds better or the loudness war problem is fixed?...

...I am just not sure if ReplayGain does fix this completely or only improve.
ReplayGain simply adjusts the volume.   It's like you re-adjust the volume control "just right" every time just-before the next song starts.   It doesn't fix the boring constant-volume music.

If you allow clipping, ReplayGain can introduce distortion.  Normally it doesn't affect sound quality at all...  It simply adjusts the volume.



Title: Re: Did I actually understand how ReplayGain and db works in music? Questions!
Post by: annalise on 2018-07-12 07:23:17
@DVDdoug

Not OP but thank you for this explanation, you helped clear up a couple of minor questions I had about replaygain as well.

Thanks!  :D
Title: Re: Did I actually understand how ReplayGain and db works in music? Questions!
Post by: harto69 on 2018-07-12 09:11:21
I'd like to thank you too
Very useful explanation!
Title: Re: Did I actually understand how ReplayGain and db works in music? Questions!
Post by: gfxnow on 2019-10-01 16:44:57
...Back to ReplayGain - If you set the ReplayGain target volume higher, two things can happen - If you allow clipping the quiet songs will get louder but may songs may get clipped.    If you don't allow clipping ReplayGain won't turn-up the volume on many songs so you might think ReplayGain isn't doing anything (and it's not doing much).

Sorry to open up an old thread but didn't want to start yet another how does replaygain work discussion.

So does that mean if most of my albums are loud (i.e. have a negative album gain value stored in the tags), the settings "apply gain and prevent clipping according to peak" (my current setting) and "apply gain" will have the same effect? Only when I play a quiet album (i.e. positive album gain value stored in the tags) could replay gain be less effective.
Title: Re: Did I actually understand how ReplayGain and db works in music? Questions!
Post by: 2tec on 2019-10-01 21:04:24
So does that mean if most of my albums are loud (i.e. have a negative album gain value stored in the tags), the settings "apply gain and prevent clipping according to peak" (my current setting) and "apply gain" will have the same effect? Only when I play a quiet album (i.e. positive album gain value stored in the tags) could replay gain be less effective.

As an end user, I'd turn it around myself, replaygain, for me, avoids effects, one, it avoids the relative effects of some songs being too loud or too quiet, and it can avoid the effects of clipping. I don't see replaygain being more or less effective, except perhaps in regards to whether the target db value is appropriate for the sort of music being played.

I hope I got that right. ;-)
Title: Re: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: gfxnow on 2019-10-02 06:03:12
I hope I got that right. ;-)

No offense but you didn't.
Title: Re: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: Case on 2019-10-02 08:36:58
So does that mean if most of my albums are loud (i.e. have a negative album gain value stored in the tags), the settings "apply gain and prevent clipping according to peak" (my current setting) and "apply gain" will have the same effect?
In principle the two settings will produce exact same results in this situation. Though if you used true-peak scanning or the source material is coded with lossy codec the peaks could be so high that clipping prevention still kicks in and further lowers the amplitude. But this is mostly a theoretical concern unless the source wasn't that loud or you use preamp to make things too loud.

Only when I play a quiet album (i.e. positive album gain value stored in the tags) could replay gain be less effective.
Correct. But if you have such material you have multiple options to combat this. Chances are the clipping is not severe and is completely inaudible. If you play the files with foobar2000's DirectSound output on anything newer than Windows XP the OS will automatically prevent clipping by compressing the peaks. And you can use Advanced Limiter DSP in foobar to achieve the same effect with any output or OS.
And you can always use the ReplayGain preamp slider to adjust the target playback level down by 6 dB. That should leave enough headroom to prevent clipping with any music material.
Title: Re: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: 2tec on 2019-10-02 12:38:26
I hope I got that right. ;-)

No offense but you didn't.

No offense eh, lol, ok, so you say, but you can't even bother to justify your statement? Or are you really just asking to be on my ignore list?
Title: Re: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: gfxnow on 2019-10-04 16:34:30
No offense eh, lol, ok, so you say, but you can't even bother to justify your statement? Or are you really just asking to be on my ignore list?

If you're so easily offended please go ahead and put me on your ignore list. I don't come here for silly arguments, just for information/knowledge which Case has very eloquently provided in his post above.
Title: Re: Do I actually understand how ReplayGain and db works in music? Questions!
Post by: yetanotherid on 2019-10-04 22:04:16
I know the original question is a bit old, but I thought I'd add this:

You can add the following as a custom column (in Playlist view etc). It'll display the ReplayGain track volume in human-speak rather than as a sound pressure level. ReplayGain's 89dBequals -18dB in human-speak. I don't know why we persist using 89dB as a target volume. The rest of the world outside ReplayGain uses a volume that makes sense to humans.

The following all highlight the playing track.

Volume Column (based on track gain)
Code: [Select]
$if(%replaygain_track_gain%,$puts(X,$sub(-1800,$replace(%replaygain_track_gain%,.,)))$puts(VOLUME,$ifequal($get(X),0,0,$ifgreater($get(X),0,$replace(+$substr($num($get(X),4),1,2),+0,+),$replace($substr($num($get(X),5),1,3),-0,-))).$substr($num($get(X),5),4,5) dB)$if(%isplaying%,>>>$get(VOLUME)<<<,$get(VOLUME)))

Track Gain Column
Code: [Select]
[$if(%isplaying%,>>>%replaygain_track_gain%<<<,%replaygain_track_gain%)]

Peak Column (based on track peak)
Code: [Select]
[$if(%isplaying%,>>>%replaygain_track_peak_db%<<<,%replaygain_track_peak_db%)]