Rockbox Technical Forums

Support and General Use => Audio Playback, Database and Playlists => Topic started by: Julian67 on October 05, 2012, 01:52:01 PM

Title: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 05, 2012, 01:52:01 PM
Currently a new default RockBox install is configured to have  "Track Gain If Shuffling" on.  This setting might more clearly be described as "Album Gain On Unless Shuffling".  I noticed several threads recently where people people encounter odd and apparently inexplicable issues with sound quality.  It's really hard to know what they mean without an audio sample, but it occured to me that the default in RockBox is not, as one might assume, to play back at the user set volume.  There is every chance that the level is being either raised or attenuated and the user does not even realise this and in fact may have checked the playback settings and even be confident that they have not enabled RG.  The attenuation is not such a big deal but the raising might be because the default is for no pre-amp adjustment and no clipping prevention so the potential is there to raise the level to undesirable levels and even induce clipping.

It seems that the default of RG Album Gain on with pre-amp 0 and no clipping prevention all presupposes that the user has very few, if any, albums with high positive album gain values and I began to wonder if that supposition was realistic so I examined my music collection:

I just looked at two parts of my collection, firstly Classical (includes Baroque, Early etc) and secondly Pop (includes any modern popular genre like Rock or Garage or Indie etc).

Of the 208 "Pop" albums only 5 have positive album gain and three of those are below 1 dB.  The highest is +3.35 dB.

Of the 819 "Classical" albums 518 have a positive album gain value(!) and of those 149 have an album_gain of +4 dB or higher.  There is one over 14 dB!  The albums with the higher values tend to be of single or duet stringed instruments, or choral works.

So I'm suggesting that the assumptions that led to RockBox's default RG settings might benefit from another look as they may cause problems for anyone who has a lot of unamplified or acoustic or vocal/choral music in their collection.  Btw this is not a complaint as it's no issue for me because quite a long time ago I Read The Fine Manual and discovered that just because I had never switched on RG didn't mean it was off!  But a typical new or uninformed user is not someone who has read the manual, and perhaps has never even heard of Replay Gain, and there is a chance that their music will play back with distortion and even severe clipping.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 05, 2012, 01:58:47 PM
The attenuation is not such a big deal but the raising might be because the default is for no pre-amp adjustment and no clipping prevention so the potential is there to raise the level to undesirable levels and even induce clipping.

The replaygain reference level is so low this will basically never matter. 
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: AlexP on October 05, 2012, 03:52:35 PM
I personally don't care one way or another, but would another solution be to turn on clipping prevention?
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 05, 2012, 04:41:22 PM
Quote from: saratoga

The replaygain reference level is so low this will basically never matter.  


I can offer an example that I believe demonstrates otherwise:

First the mediainfo:

Code: [Select]
General
Complete name                            : 06 - Dulces exuviæ.ogg
Format                                   : OGG
File size                                : 6.77 MiB
Duration                                 : 4mn 50s
Overall bit rate mode                    : Variable
Overall bit rate                         : 195 Kbps
Album replay gain                        : 5.57 dB
Album replay gain peak                   : 0.982951
Album                                    : Spanish songs & vihuela solos
Track name                               : Dulces exuviæ
Track name/Position                      : 6
Performer                                : Catherine King & Jacob Heringman
Composer                                 : Alonso Mudarra
Genre                                    : Renaissance
Recorded date                            : 1997-01-01
CATEGORY                                 : classical
CDID                                     : b9104520

Audio
ID                                       : 602039608 (0x23E26538)
Format                                   : Vorbis
Format settings, Floor                   : 1
Duration                                 : 4mn 50s
Bit rate mode                            : Variable
Bit rate                                 : 224 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Replay gain                              : 4.46 dB
Replay gain peak                         : 0.764122
Stream size                              : 7.75 MiB
Writing library                          : libVorbis (Everywhere) (20100325 (Everywhere))

This is ripped from my own CD to flac and subsequently encoded to Ogg Vorbis and the Replay Gain values being calculated by vorbisgain in album mode (vorbisgain -a <album_directory>)

The file: http://www.filefactory.com/file/3oy3lhxu2f59/n/06_-_Dulces_exuvi_ogg (http://www.filefactory.com/file/3oy3lhxu2f59/n/06_-_Dulces_exuvi_ogg)

Listen to it from 2m 0s to 2m 4s with RG album mode, no pre-amp, no clipping prevention.  Then listen with RG disabled.  There simply is no way to not notice the very unpleasant distortion even when played back with Rockbox volume level set to -20 dB.

Quote from: AlexP
I personally don't care one way or another, but would another solution be to turn on clipping prevention?

Yes, I think that would be a sane default configuration for Rockbox (probably more acceptable for some people than my original suggestion to switch it off by default) and suspect it might eliminate some of these apparently inexplicable "I tried Rockbox and it sounds bad" posts from new users.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 05, 2012, 05:28:43 PM
I should say almost never.  I've never seen this on music I use, but its certainly possible.  If you want, submit a patch. 
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 05, 2012, 06:43:49 PM
I should say almost never.  I've never seen this on music I use, but its certainly possible.  If you want, submit a patch.  

Yes but your "almost never" is based entirely on "music I use" which is an unknown quantity (except to you) and is essentially unquantifiable.  There is zero data, only an assertion or opinion.

What I tried to demonstrate is:

In a collection of modern, amplified music (rock, pop, indie, contemporary African, Cuban etc etc) then positive replay gain values are indeed seen "almost never".

In a collection containing lots of unamplified music or lots of non-orchestral "classical" music then high positive album gain values are definitely encountered and are not even unusual, they are far more usual than the negative gain values found in amplified music.  You might even call them normal or unremarkable.

I've then demonstrated that with the default Rockbox config an album gain value of 5.57 dB being applied can induce severe distortion even at low output levels.  That value of 5.57 dB is not an extreme value likely to be encountered "almost never".   63% of my classical collection has a positive album gain value and of those 97 albums have an album gain value above 4 dB, which is more than 11% of my classical collection.

A default setting in a playback app or firmware that demonstrably induces obvious audible artefacts and even severe clipping might not be a great default.  The fact that it's a reasonable setting for people whose collection is entirely or almost entirely composed of amplified music where a positive gain value is almost never seen doesn't mean that it's a reasonable global default.

I'm sorry to labour the point but it's quite difficult to engage with short assertions that seem more like obstacles than exchanges, so I just try to explain it again as clearly as I know how.

I'm unsure why you suggest to submit a patch.  What exactly would be patched?  After looking at a default .rockbox and at a source tree I'm still unsure where or how Rockbox initial default config is defined or why a patch from a user is required to do something that requires zero new code and which is transparently easy for any Rockbox developer but may be problematic for an end user.  I'm suggesting that the default config has a problem which Rockbox release manager/team/whoever might like to consider and modify if they agree.  I've identified a problem and tried to provide both information, reasoning and a practical demonstration to illustrate this beyond any doubt.  If raising the issue in the forum is not the right approach then wouldn't "file a bug report" is the next step, not "submit a patch"?

To conclude, I'll just refer back to my reply to AlexP in my previous post and apologise for disturbing you.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 05, 2012, 07:51:37 PM
I mean that I don't mind if someone else wants to change it.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 05, 2012, 08:01:43 PM
Ah ok..... ;D

If anyone prefers I submit a bug report please say so.  If a patch is preferred please give me a start by pointing out which file in the source tree is relevant and I will submit a badly formatted patch fully ready for rejection (hint: it's better if someone familiar with the source and the style does it).
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: AlexP on October 06, 2012, 02:50:38 PM
I don't think anyone would mind turning on clipping prevention by default.  I don't think a bug report is appropriate as a it isn't a bug per se, more a change in behaviour.

I'll have a fiddle.

Edit:  It is a one word change on one line, so easy peasy.  If none of the other devs object (can't see why they would) I'll change it soon.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 07, 2012, 08:06:39 AM
Thanks for your time and consideration.  I hope the change will mean nobody who tries Rockbox will have sound quality issues at default settings, and hopefully there will be fewer odd "my music doesn't sound right" threads/posts/complaints.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: xpmule on October 07, 2012, 07:02:22 PM
interesting.
i make sure my collection ALWAYS has album and track gain tags.
but i don't usually use it at all but would prefer it off by default myself.
if people know what it is I'm sure they will investigate how to turn it on if needed.

i wonder though is the config for it the standard reference settings ?

in case some viewers don't know what this is about see this page maybe..
http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification

and maybe google "Loudness Wars"
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 07, 2012, 09:33:09 PM
interesting.
i make sure my collection ALWAYS has album and track gain tags.
but i don't usually use it at all but would prefer it off by default myself.

I do much the same.  My transcoding process is automated: it requires no effort from me to have RG data added to the metadata so it's done.  I don't usually use RG but have set up my transcode script to add RG data because it may be useful sometimes/occasionally/one day, maybe.  

Quote from: xpmule
if people know what it is I'm sure they will investigate how to turn it on if needed.

This would be my assumption as well and I do find it really surpising that such an intrusive mechanism would be on by default in any audio player.  It seems to presume that the listener listens to a random selection of amplified music.  My assumption would be that I have no idea who the listener is or what they like so vanilla makes the best default and let the person doing the tasting add the syrup.  Definitely don't hide a raw chilli pepper in the middle.

I've encountered several times the idea that RG is almost certain not to cause audible distortion/artefacts so is de facto harmless.  But this is only assured to be true for gain values of zero or lower.  I think I've demonstrated with the sample I linked that in fact RG can cause severe distortion even at a playback level well below minus 20 dB.  And that is with a track which is never, ever going to clip under normal conditions:

(http://img585.imageshack.us/img585/3771/06deaudacity.jpg)

There seems to be a widely accepted but erroneous assumption that positive album gain values are unusual and that very high album gain values (i.e. 4 dB and higher) are almost unheard of.  But as soon as you move away from amplified music and into the arena of unamplified music then positive album gain values are the norm and very high values are found surpisingly often.

Replay Gain makes sense in a world where its application means attenuation or very tiny amplification.  But that "world view" is actually quite narrow:  there are multiple traditions of unamplified music with vast repertoires and huge numbers of recordings and listeners.  People didn't stop listening to Bach, Handel, Palestrina et al, or to Indian or Arabian classical or west African traditional music (lots of unamplified strings).  Almost all of it will have positive RG values which if applied can make some of it clip.  For anyone who listens only to amplified music this doesn't matter even a little bit, but for several billion other people it makes a difference.

RG with clip protection is a much better default than RG without, but it still poses a problem which is that the clip protection works on a per-track basis and can make big differences to the relative loudness between adjacent tracks.  There are plenty of albums which are gapless where the track split points are in effect index points in the middle of unbroken audio, and even more albums where the tracks form part of a single work (they are intended to only ever be heard together and in a particular coherent sequence).  It's really hard to think of anything positive to say about a mechanism which at a musically arbitrary point might attenuate or raise the level by several dB.

Anyway enabling clip protection is a good move as at least nobody is going to risk damaging their headphones, or find themselves pulling their buds out as quick as they can before posting a complaint about squelching, upper harmonic distortion or whatever term is currently preferred for "it sounds awful, it made me cry and my ears still hurt".

I have to go now as my new Hannah Montana Forever Soundtrack download has completed and I can't wait to make a karaoke mix and then spend the night singing along....
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 07, 2012, 09:55:10 PM
You don't need to demonstrate that the 89 db reference level can cause clipping.  This has been known for over a decade. 89 db was chosen over the safer 83 db because it was extremely rare for clipping to occur and so 83 db was judged to not be worthwhile.  But it can occur, particularly if your music is mastered oddly.  Its just extremely rare.

Clipping protection isn't a bad idea, but Most clipping isn't audible and in fact nearly all modern music clips a bit in mp3 format. So if you enable it you will have less effective volume equalization but little gain except for exceptional tracks.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 08, 2012, 09:37:35 AM
Quote from: saratoga
...Its just extremely rare.

Yes but that's an assertion, not a fact, and it only holds good with amplified music, which seems to have led to it being generally accepted.  My point was that with unamplified music that "extremely rare" situation is encountered a lot less rarely, and nothing has to be "mastered oddly".   "Loudness War" mastering basically doesn't exist in classical music; full dynamic range is the aim (and the norm) and the less compression the better.  Another example:

This time the positive album gain is only 1.63 dB

Code: [Select]
TITLE=God is with us
ARTIST=John Tavener
ALBUM=Byzantia
TRACKNUMBER=02
GENRE=Classical
COMPOSER=John Tavener
REPLAYGAIN_TRACK_PEAK=0.98935145
REPLAYGAIN_TRACK_GAIN=-3.15 dB
REPLAYGAIN_ALBUM_PEAK=0.98935145
REPLAYGAIN_ALBUM_GAIN=+1.63 dB

(http://img825.imageshack.us/img825/915/byzantia02.jpg)

http://www.filefactory.com/file/2fmdp7je1bjx/n/02_-_God_is_with_us_ogg (http://www.filefactory.com/file/2fmdp7je1bjx/n/02_-_God_is_with_us_ogg)

This clips at about 5m 30s if album gain is applied (hard clicks in both channels), exactly as you'd expect when looking at the waveform and wondering what would happen if you added another dB or two at 5m 30s.....

And another, this time an orchestral work:

Code: [Select]
TITLE=Sinfonía Sevillana: 3
TITLE=Fiesta en San Juan de Aznalfarache
ARTIST=Orquesta Filarmonica de Gran Canaria, Adrian Leaper
ALBUM=Sinfonía Sevillana
DATE=1999-01-01
TRACKNUMBER=3
GENRE=Classical
COMPOSER=Turina
REPLAYGAIN_TRACK_PEAK=0.98125243
REPLAYGAIN_TRACK_GAIN=+1.99 dB
REPLAYGAIN_ALBUM_PEAK=0.98125243
REPLAYGAIN_ALBUM_GAIN=+3.49 dB

(http://img850.imageshack.us/img850/6049/turinafiesta.jpg)

http://www.filefactory.com/file/58supg72nnj/n/03_-_Sinfon_a_Sevillana-_3_-_Fiesta_en_San_Juan_de_Aznalfarache_ogg (http://www.filefactory.com/file/58supg72nnj/n/03_-_Sinfon_a_Sevillana-_3_-_Fiesta_en_San_Juan_de_Aznalfarache_ogg)

This one is more typical of what many people think of as classical music - it's orchestral and ends with a loud crescendo.  It's very loud indeed and there are lots of instruments making lots of sounds and you could probably listen to that crescendo with RG album mode and not think anything was amiss, but listening again without any RG it becomes clear that RG did indeed introduce distortion.  It isn't as obvious as hard clicks or or a soprano's voice breaking up and it's easy to see how people might describe it in various terms that are hard to quantify and hard to understand by anyone not sharing the experience.

The tracks I've used as examples are not oddly mastered or unusual repertoire.  You could go through any collection of unamplified music and find lots of albums containing tracks using a full dynamic range and for which RG processing will have applied a positive album gain higher than the track gain, at which point you've introduced the possibility of clipping.

tl ;dr summary:

It isn't extremely rare, it's only as rare as unamplified music - it's very common!

Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 08, 2012, 10:46:14 AM
tl ;dr summary:

It isn't extremely rare, it's only as rare as unamplified music - it's very common!



Yes, but such music is just a tiny fraction of all the music out there hence the compromise.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: gevaerts on October 08, 2012, 11:02:03 AM
tl ;dr summary:

It isn't extremely rare, it's only as rare as unamplified music - it's very common!



Yes, but such music is just a tiny fraction of all the music out there hence the compromise.

Maybe, but I'd say for a specific user either zero (or almost zero) tracks show the issue, or nearly all of them.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: cereal_killer on October 08, 2012, 01:51:53 PM
Wow, impressive discussion going on here. I am no audiophile and my technical knowledge is not enough to fully understand what replay gain does, or how rockbox works regarding that, but I dare to put my 2 cents in.

I was surprised, hearing that a feature in rockbox, that is somehow processing and changing the sound output is on by default. I personally would prefer if everything is off and I could choose to switch a setting on if needed. Even if the effect is not noticeable for the kind of music I have on my player.

Surely the following comparison is not valid, but I wouldn't like an EQ setting to be on by default either. I like every sound setting turned off (no EQ, no bass or treble enhancement...) Obviously replay gain is a good thing and I think I need to look into that.

Greetings,

c_k
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: saratoga on October 08, 2012, 08:20:46 PM
I was surprised, hearing that a feature in rockbox, that is somehow processing and changing the sound output is on by default. I personally would prefer if everything is off and I could choose to switch a setting on if needed. Even if the effect is not noticeable for the kind of music I have on my player.

Its only on if you've scanned your files with replaygain.  And if for some reason you scanned your files with replaygain tags for purposes of not using replaygain tags, you can disable it using the setting we provide. 

Yes, but such music is just a tiny fraction of all the music out there hence the compromise.

Maybe, but I'd say for a specific user either zero (or almost zero) tracks show the issue, or nearly all of them.

Thats the annoying thing about defaults, they're never right for everyone.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 09, 2012, 02:52:37 PM
Quote from: saratoga
Quote from: Julian67
.........it's only as rare as unamplified music - it's very common!

Yes, but such music is just a tiny fraction of all the music out there hence the compromise.

It might be true that there has been more amplified music recorded than unamplified but there again it might not be (data? facts?), but  "a tiny fraction"?  The vast catalogues of Decca, Universal, Deutsche Grammophon, HMV, EMI, Mercury et al are so insignificant that they can be casually dismissed?

It's a truism that defaults can never be right for everyone.

I would say that RG with clip prevention (might change relationship between adjacent tracks but will anyone notice?) is a compromise between vanilla (never degrades audio; works for everyone) and current default (may degrade audio; works brilliantly for some but is very bad for others).  Obviously I think vanilla is the saner setting for a global default but the incumbent always has inertia and familiarity, and such is the nature of compromise....

I doubt very strongly indeed the validity of the presumptions that having unamplified music in a collection is unusual, or that having lots of it is extremely rare.  Reasoning based on those premises is inherently flawed (unless the resulting action applies only to oneself) because it's generalising from the personal and particular.

Quote from: gevaerts
Maybe, but I'd say for a specific user either zero (or almost zero) tracks show the issue, or nearly all of them.

Clearly there are people who have only amplified music and probably some who have only unamplified, but can I propose that having some or lots of both in varying proportions is not at all unusual?

Quote from: saratoga
And if for some reason you scanned your files with replaygain tags for purposes of not using replaygain tags, you can disable it using the setting we provide.

Actually I'm not being perverse in applying RG tags to my collection.  A few years ago I did a big, laborious tidy up of my collection's directory and file names and metadata and being aware of RG realised this was a good time to try it.  But I found it impossible to assess RG without the RG tags  ;)  so I tagged my existing collection and modified my transcode process (flac to ogg or mp3) to include album gain for future encodes.  As stated earlier it's automated (scripted and aliased) so it's no extra (human) work.  After running into instances of distortion and sometimes bad clipping I looked at why this might be and realised that positive album gain values can leave you with four choices:

i) a pre-amp value so low that some tracks are ridiculously quiet

ii) the possibility of distortion/clipping

iii) applying clip-prevention and having the relationship between some adjacent tracks artificially altered.

iv) switch it off

So I went back to using the volume buttons for the most part, but if I make a playlist of rock or pop etc then RG becomes useful and I can toggle it on.

You might recall that in my original post I pointed out that beyond the actual benefits/disadvantages of RG there is the issue that it isn't obvious to any new or casual user of Rockbox that RG is even enabled because the menu item is highly ambiguous:

"Track Gain If Shuffling"  For anyone discovering Rockbox by using it (default male human behaviour since forever), or to anyone who doesn't know what Replay Gain is, then that is in no way a declaration that RG in album mode is on or that the player perhaps isn't doing what you think it is doing.

I'll repeat what I posted previously because I think it's valid and doesn't have a logical or practical weakness:

"I have no idea who the listener is or what they like so vanilla makes the best default and let the person doing the tasting add the syrup.  Definitely don't hide a raw chilli pepper in the middle."
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: bluebrother on October 09, 2012, 06:04:03 PM
This discussion is really getting useless. Both parties claim that their "default" type of music is a relevant portion but neither provides numbers. Just listing a couple of labels doesn't help any way -- there are enough labels to list for the opposite argument as well. Also, the number of labels or records is totally irrelevant -- if any the most common type of a typical Rockbox user would be of interest. We don't have any data for this afaik, but given that younger people are more familiar with computer stuff and therefore likely to be the majority of Rockbox users, and younger people (at least seem to) be rather on the pop side the current default matches simply a greater number of Rockbox users.

Instead of arguing about music types other questins should be answered: are there any side effects when enabling "prevent clipping" like degrading of audio quality for normal playback? How much processing power does enabling it by default cost? Are there other reasons to not enable it by default?

I.e. are there reasons good enough to change the default behaviour or are there important reasons against it?
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: torne on October 10, 2012, 09:47:14 AM
I had a look at the code and it looks like clipping prevention is "free", as it just uses the RG tag's recorded peak level to determine whether the level of gain specified will cause clipping and caps it if so. Unless I've misinterpreted the implementation the only downside will be that music with a positive gain adjustment will sometimes sound quieter than other tracks (and if clipping prevention is not turned on there, it *may* have produced audible clipping instead).

Let's just turn clipping prevention on by default as well.
Title: Re: Would it be better for Replay Gain to be off by default?
Post by: Julian67 on October 12, 2012, 07:18:19 PM
... music with a positive gain adjustment will sometimes sound quieter than other tracks (and if clipping prevention is not turned on there, it *may* have produced audible clipping instead).

As far as I can tell this is indeed the result of running RG with clip prevention.  The upside is no more potential for clipping or harmonic distortion, while the downside is that adjacent tracks on some albums will have different relative loudness than on the CD (or other source).  This is odd and defnitely not an effect anyone might seek out, but it's usually not going to be easily apparent like clipping or harmonic distortion and will usually require great familiarity with a  recording, or side by side CD vs File playback comparison, to identify it.  It's hard to see "a fault that will occasionally occur but probably not be noticed" as an ideal default when it's equally easy to achieve unmanipulated playback, but it's a huge improvement on current release default.

Old farts with beards talk about "a wire with gain" but I shaved this morning.