When encoding files in CBR mode (potentially ABR as well, yet to be properly explored), quality for various audio samples degrade when selecting higher quality settings than -q 4.
There's a discussion over at HydrogenAudio. I summarized my findings in following posts:
https://hydrogenaud.io/index.php/topic,126120.msg1046452.html#msg1046452 (in short: noise_shaping_amp makes the difference between -q 0 and -q 4)
https://hydrogenaud.io/index.php/topic,126120.msg1046480.html#msg1046480 (in short: The difference between -q 0 and -q 4 is easily ABXable at 128 kbps, with -q 0 showing obvious artifacting)
My current hypothesis on what may be happening: If noise_shaping_amp is set to 1 or 2 (higher quality settings), only one or some bands will receive a boost if the noise threshold is exceeded (c.f. function amp_scalefac_bands in quantize.c). In CBR, when increasing quality for some bands, the encoder can not simply select a higher bitrate to accommodate the boosted band(s), so the non-boosted bands will be quantized more heavily or collapse completely.
With -q 4 (or even faster settings), noise_shaping_amp is set to 0. In this mode, all bands that exceed the noise threshold receive boost. In bitrate-constrained operation (where it's impossible to select a higher bitrate), this seems to spread quantization more evenly across bands and generally avoids that bands collapse completely.
The fix appears to be rather easy: Setting noise_shaping_amp to 0 for CBR encodes avoids the observed quality degradation in my tests.
For some reason, I accidentally filed this in group "Compatibility". More fitting would be "Quality", of course.
Here's a trivial patch that sets
noise_shaping_ampto0for CBR encoding.ABR seems to be affected similarly to CBR. Here's a slightly expanded trivial patch to disable
noise_shaping_ampfor ABR as well.The problem of q0/q1/q2/q3 producing worse results for CBR/ABR was introduced with this change:
https://sourceforge.net/p/lame/svn/6147/
This enabled the new VBR-psymodel for CBR and ABR, which happened to help with https://sourceforge.net/p/lame/bugs/392/ (which also is about lower speed settings introducing artifacts).
Here's another patch approach: This makes -q4 the lowest quality setting (providing the best quality) for CBR and ABR. This is similar how for the new VBR mode, some quality settings are disallowed as well (a few lines prior).
Last edit: Paul Smith 2025-05-28
This should not be platform-specific.
Note, however, that at a high bitrate such as 320 kbps, it's rather unexpected to find cases where one "sounds way better" than the other. Did you check your findings via ABX testing?
fantastic patch here i got to say can i ask exactly what modifications you made? cause even at 320kpbs -q0 i can hear a difference with your version i couldn't with my airpods.. but then tested with focal lensys pro studio headphones and you can really notice it then even at 320kbps.
i mix and master music for a living and your patch version might be the best quality mp3 ive ever heard atleast for CBR anyway
is it safe to use to this version? cause i want to start using it going forward
and this patch needs to be implemented in the next version of LAME to be honest its a critical bug
The patch disables a quality optimization that targeted the old psychoacoustic model. The old model has been removed years ago, but the optimization has been kept in place and reduces quality with the new model.
The patch should be very safe to use, but you can also just use the latest official version and disable the offending code by specifying the "-q 4" command line switch.
In case you have seen my last reply via email notification: forget about it. I found a different testing corpus which narrows down the issue to the setting of noise_shaping_amp with -q3. A fix for this may be in 4.1.
A fix is in the development version /only q3 and q1. this will be in 4.1.