Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Why does Sox (cli) automatically apply dither when only changing sampling rate? (Read 6339 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Why does Sox (cli) automatically apply dither when only changing sampling rate?

As far as I understand it dither is only useful when reducing bit depth. I'm curious why then the sox command line utility chooses to apply dither (according to -V) when only changing sample rate:

Code: [Select]
sox -V 01\ Enter\ The\ Machine.flac -r 48k /tmp/test.wav

sox:      SoX v14.4.2
sox INFO formats: detected file format type `flac'

Input File     : '01 Enter The Machine.flac'
Channels       : 2
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:02:02.25 = 5391372 samples = 9169 CDDA sectors
File Size      : 14.5M
Bit Rate       : 951k
Sample Encoding: 16-bit FLAC
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no
Comments       :
<snip>
sox INFO sox: Overwriting `/tmp/test.wav'

Output File    : '/tmp/test.wav'
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Duration       : 00:02:02.25 = 5868160 samples ~ 9169 CDDA sectors
Sample Encoding: 16-bit Signed Integer PCM
Endian Type    : little
Reverse Nibbles: no
Reverse Bits   : no
Comments       :
<snip>
sox INFO sox: effects chain: input        44100Hz  2 channels
sox INFO sox: effects chain: rate         48000Hz  2 channels
sox INFO sox: effects chain: dither       48000Hz  2 channels
sox INFO sox: effects chain: output       48000Hz  2 channels
sox WARN rate: rate clipped 1553 samples; decrease volume?
sox WARN dither: dither clipped 1365 samples; decrease volume?

I don't understand, why is it applying dither here. Is it safe to just manually disable dither in this scenario? I've read somewhere to let sox just do what it wants to do because it knows best...

Re: Why does Sox (cli) automatically apply dither when only changing sampling rate?

Reply #1
The 16bit input is calculated at higher bitdepth and dithered back to 16bit for the output. For 24bit output it doesn't. You can disable dither if you have a reason.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Re: Why does Sox (cli) automatically apply dither when only changing sampling rate?

Reply #2
I'm not sure I understand... Why is Sox internally converting to a higher bit depth then?

I found this relevant information on the sox website:

Code: [Select]
Specifically, by default, SoX automatically adds TPDF dither when the output bit-depth is less than 24 and any of the following are true:


• bit-depth reduction has been specified explicitly using a command-line option


• the output file format supports only bit-depths lower than that of the input file format


• an effect has increased effective bit-depth within the internal processing chain

For example, adjusting volume with vol 0.25 requires two additional bits in which to losslessly store its results (since 0.25 decimal equals 0.01 binary). So if the input file bit-depth is 16, then SoX’s internal representation will utilise 18 bits after processing this volume change. In order to store the output at the same depth as the input, dithering is used to remove the additional bits.

It's not clear to me how any of the 3 points applies. If I understood you right you're talking about the third point, but I'm not changing volume...

Edit: Oh, I think I have an idea why... When it is upsampling it has to create new samples... Basically interpolating their amplitude in regards to its neighbours. If the accuracy of 16 bit didn't suffice to accurately represent the value of the new sample it uses a higher internal representation and has to dither to go back to 16 bit?! ... Maybe?

Re: Why does Sox (cli) automatically apply dither when only changing sampling rate?

Reply #3
Resampling creates a lot of higher frequencies, which need to be filtered out.

Filtering involves many, many multiply/add operations.

If the filtering were carried out at 16 bit resolution then roundoff errors would accumulate and add significant noise.

Therefore filtering is done at higher resolution, and dithering is applied when reducing to 16 bits.

Re: Why does Sox (cli) automatically apply dither when only changing sampling rate?

Reply #4
Basically meaning...  Don't increase the source sample rate. 

It's like up converting a 128 kbps mp3 to 320 kbps...  There is no benefit, unless you like larger files, and you lose quality.
JXL