The following command:
sox -G input.flac -b 16 output.flac
prints: WARN dither: dither clipped 136 samples; decrease volume?
But this command, which I thought should be equivalent, does not:
sox input.flac -b 16 output.flac gain -h dither -s
Is that expected behavior?
Below are logs when run with -V -V:
sox -V -V -G input.flac -b 16 output.flac
Input File : 'input.flac'
Channels : 2
Sample Rate : 44100
Precision : 24-bit
Duration : 00:08:41.00 = 22976100 samples = 39075 CDDA sectors
File Size : 86.4M
Bit Rate : 1.33M
Sample Encoding: 24-bit FLAC
Endian Type : little
Reverse Nibbles: no
Reverse Bits : no
sox INFO flac: encoding at 16 bits per sample
Output File : 'output.flac'
Channels : 2
Sample Rate : 44100
Precision : 16-bit
Duration : 00:08:41.00 = 22976100 samples = 39075 CDDA sectors
Sample Encoding: 16-bit FLAC
Endian Type : little
Reverse Nibbles: no
Reverse Bits : no
sox DBUG dither: mult=0.999969
sox DBUG output: mult=0.999969
sox INFO sox: effects chain: input 44100Hz 2 channels (multi) 24 bits 00:08:41.00
sox INFO sox: effects chain: gain 44100Hz 2 channels 24 bits 00:08:41.00
sox INFO sox: effects chain: dither 44100Hz 2 channels 16 bits 00:08:41.00
sox INFO sox: effects chain: output 44100Hz 2 channels (multi) 16 bits 00:08:41.00
sox WARN dither: dither clipped 136 samples; decrease volume?
sox -V -V input.flac -b 16 output.flac gain -h dither -s
Input File : 'input.flac'
Channels : 2
Sample Rate : 44100
Precision : 24-bit
Duration : 00:08:41.00 = 22976100 samples = 39075 CDDA sectors
File Size : 86.4M
Bit Rate : 1.33M
Sample Encoding: 24-bit FLAC
Endian Type : little
Reverse Nibbles: no
Reverse Bits : no
sox INFO flac: encoding at 16 bits per sample
Output File : 'output.flac'
Channels : 2
Sample Rate : 44100
Precision : 16-bit
Duration : 00:08:41.00 = 22976100 samples = 39075 CDDA sectors
Sample Encoding: 16-bit FLAC
Endian Type : little
Reverse Nibbles: no
Reverse Bits : no
sox DBUG dither: mult=0.998589
sox DBUG output: mult=0.998589
sox INFO sox: effects chain: input 44100Hz 2 channels (multi) 24 bits 00:08:41.00
sox INFO sox: effects chain: gain 44100Hz 2 channels 24 bits 00:08:41.00
sox INFO sox: effects chain: dither 44100Hz 2 channels 16 bits 00:08:41.00
sox INFO sox: effects chain: output 44100Hz 2 channels (multi) 16 bits 00:08:41.00
Same here.
See also https://stackoverflow.com/questions/6882125/reducing-removing-clipping-in-sox-when-converting-the-sample-rate#comment128663369_6890216
Actually, after a bit of experimenting, the difference is not beween the global
-Goption and the explicitgaineffect. Instead, it's the-soption of thedithereffect that makes the difference. The-soption selects the Shibata noise-shaping filter fordither.There are three cases:
The first two are identical; both will clip samples (dependent on the pseudo-random noise generated, of course). The third one is the only one that selects the Shibata noise-shaping filter for
dither, and will not clip samples.https://codeberg.org/sox_ng/sox_ng/issues/256