HydrogenAudio

Lossless Audio Compression => FLAC => Topic started by: bmcelvan on 2016-12-06 17:21:28

Title: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 17:21:28
I'm converting 24bit/96kHz FLAC files to both mp3 and 16bitFLAC files.

I've already determined for mp3 I will keep the source files at 24bit but downsample to 44.1 and then run through LAME since it can accept 24bit source files and I won't have to deal with the dithering issue.

I chose 44.1 as it will create smaller file sizes than 48kHz and I can't tell any difference between 44.1 and 48kHz audio files thru abx testing.

However my real question is about what to do for the FLAC files in regards to dithering. I figured I'd take the .mp3 input 24/44.1 file and then use SoX to convert to 16bit. Should I dither or not for this process?

Technically speaking, when using dithering doesn't it potentially increase the dynamic range of a 16bit file? What are the advantages/disadvantages of not dithering?

These FLAC files would be my long term archive files (as well as listening files when I'm home and/or have access to them). The .mp3s would be my traveling/portable set of files.

Any advice?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: KozmoNaut on 2016-12-06 17:29:13
It's unlikely that you would be able to hear the difference, but the generally accepted advice is to use dither whenever converting to 16bit or less.

For SoX, the command line would be:
sox <infile> -b 16 <outfile> rate 44100 dither -s


For noise shaped dither at the default recommended settings.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: pdq on 2016-12-06 17:36:01
Why do you think that the 44.1 files will be smaller than 48?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 17:41:20
It's unlikely that you would be able to hear the difference, but the generally accepted advice is to use dither whenever converting to 16bit or less.

For SoX, the command line would be:
sox <infile> -b 16 <outfile> rate 44100 dither -s


For noise shaped dither at the default recommended settings.


Thanks for the response.

Another question for you then...as you mention the command line. I've been using foobar (Win7) and the SoX add-on element in the foobar program for all converting:
24-bit to 16-bit I've been doing that thru the foobar convert-->WAV (16bit) and dither always or never.
48kHz (or greater) to 44.1kHz, I've been doing that thru foobar convert-->processing-->SoX and using the defaults there with the high quality option (95%, no aliasing & 50% phase response (linear).

Should I use the command line instead of foobar-->SoX for the downsampling? Is it technically better for transparent conversion?
Should I use the SoX command line for the entire conversion, downsample and bit depth change for the same reasons above, is it better than the foobar GUI?

thanks so much

I assume I can get the SoX command line tools from sourceforge?
and will it accept *.* for command line functions to a batch of files?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 17:43:50
Why do you think that the 44.1 files will be smaller than 48?

They always are when I convert the same source file to both versions.

Should it not be that way - isn't it technically storing more information (provided there is signal in that extra 4kHz) even if I can't hear it?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-06 17:50:06
Is it technically better for transparent conversion?
Transparent means audibly indistinguishable, therefore you can only obtain an answer through a proper listening test.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: KozmoNaut on 2016-12-06 17:52:06
Should I use the command line instead of foobar-->SoX for the downsampling?

You're using the default options, so you'll get the same results as on the command line.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: pdq on 2016-12-06 18:01:02
Why do you think that the 44.1 files will be smaller than 48?

They always are when I convert the same source file to both versions.

Should it not be that way - isn't it technically storing more information (provided there is signal in that extra 4kHz) even if I can't hear it?
If you are converting to cbr files then the size will be identical regardless of sample rate. If you are converting to vbr then there is a target quality, which may or may not require more bits. Also, the encoder tries very hard not to use bits for something that you cannot hear.

Then there is sfb21...
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: Porcus on 2016-12-06 18:37:15
However my real question is about what to do for the FLAC files in regards to dithering. I figured I'd take the .mp3 input 24/44.1 file

FLAC -> MP3 -> FLAC? Why?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 19:13:56
If you are converting to cbr files then the size will be identical regardless of sample rate. If you are converting to vbr then there is a target quality, which may or may not require more bits. Also, the encoder tries very hard not to use bits for something that you cannot hear.

Then there is sfb21...

Sorry if this was confusing and to Porcus point I think it is clear that it was.
What I'm doing is: 1 MP3 & 2 FLAC
1 - 24/96 FLAC-->24/44.1WAV-->LAME MP3
2-                                            -->16/44.1 FLAC

In regards to .mp3 filesize, I see your point. However I was referring to FLAC filesizes although that was very confusing, sorry. Also, maybe it's just principle but I don't see a reason to encode anything that I can't hear. For .mp3 I use -v2 but even for my archives...I know I cannot hear anything above 18.5-19.0 kHz. My son who is 4 years old so has great ears can't hear anything above 20.0-20.5kHz so i don't see a need to keep anything higher than that in my FLACs and just waste HDD space.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 19:17:53
Should I use the command line instead of foobar-->SoX for the downsampling?

You're using the default options, so you'll get the same results as on the command line.

KozmoNaut:
If I simply use the foobar GUI-->convert-->output WAV (16bit DITHER ALWAYS) and the SoX resampler with no aliasing, 95% passband, and 50% phase, that will yield the same results as using the SoX command line of:
sox <infile> -b 16 <outfile> rate 44100 dither -s

One more question as I read someone post somewhere that when converting like this sometimes the audio can get clipped. Using --guard or something like that in SoX command line will prevent, rather warn about clipping and the volume can be reduced to prevent clipping.

Can I assume using the foobar SoX you won't get that warning? Seems like reason enough to use command line, or am I missing something?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-06 19:25:16
Foobar GUI has differently - (more) strongly shaped dither than SoX's dither -s.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 19:36:43
Foobar GUI has differently - (more) strongly shaped dither than SoX's dither -s.

It looks as though you're implying command line is better?

What about the clipping issue and using the --guard option. Think it's worth switching to the command line for this?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-06 19:40:25
Foobar GUI has differently - (more) strongly shaped dither than SoX's dither -s.

It looks as though you're implying command line is better?

What about the clipping issue and using the --guard option. Think it's worth switching to the command line for this?

Not neccesarily better - different.

I would not worry about clipping if it occurs very rarely.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-06 19:40:42
It looks as though you're implying command line is better?
He won't be able to comment on any sound quality differences without breaking TOS8, so I'd pay him no mind.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-06 19:55:05
It looks as though you're implying command line is better?
He won't be able to comment on any sound quality differences without breaking TOS8, so I'd pay him no mind.

And what type of dither would you recommend for 16 bit tracks for routine workflow?
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: KozmoNaut on 2016-12-06 19:55:21
KozmoNaut:
If I simply use the foobar GUI-->convert-->output WAV (16bit DITHER ALWAYS) and the SoX resampler with no aliasing, 95% passband, and 50% phase, that will yield the same results as using the SoX command line of:
sox <infile> -b 16 <outfile> rate 44100 dither -s

One more question as I read someone post somewhere that when converting like this sometimes the audio can get clipped. Using --guard or something like that in SoX command line will prevent, rather warn about clipping and the volume can be reduced to prevent clipping.

Can I assume using the foobar SoX you won't get that warning? Seems like reason enough to use command line, or am I missing something?

Yes, that should give you the default same results as that command line. I'm not 100% sure about the options set "behind the scenes" in the plugin, but it should be using noise-shaped dither and clipping protection, AFAIK.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-06 20:02:45
And what type of dither would you recommend for 16 bit tracks for routine workflow?
Sans double blind test results demonstrating a difference (let alone a preference), the defaults will be adequate.  As for which resampler, I would go with the one that is most efficient (which I guess is SoX, based on what little research I've done on the subject).
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bennetng on 2016-12-06 20:24:33
What I'm doing is: 1 MP3 & 2 FLAC
1 - 24/96 FLAC-->24/44.1WAV-->LAME MP3
2-                                            -->16/44.1 FLAC
If you cannot hear the differences of dither vs truncate (no dither), then it is wiser not to use dither when encoding to 16-bit flac since the noise used in dither is hard to encode which may yield bigger 16/44 flac files.

Also, with foobar2000, you don't need to manually create any intermediate 24/44 wav files. Just set the SoX resampler to output 44k and encode to mp3 directly. All kinds of intermediate bit-depth conversion, when needed, will be automatically performed.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-06 20:34:40
And what type of dither would you recommend for 16 bit tracks for routine workflow?
Sans double blind test results demonstrating a difference (let alone a preference), the defaults will be adequate.  As for which resampler, I would go with the one that is most efficient (which I guess is SoX, based on what little research I've done on the subject).

Alright. Reasonable approach.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-06 20:37:28
If you cannot hear the differences of dither vs truncate (no dither), then it is wiser not to use dither when encoding to 16-bit flac since the noise used in dither is hard to encode which may yield bigger 16/44 flac files.
"May" being the operative, as the least significant bit(s) in the truncated file could very easily be uncorrelated noise as well.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 20:43:00
KozmoNaut:
If I simply use the foobar GUI-->convert-->output WAV (16bit DITHER ALWAYS) and the SoX resampler with no aliasing, 95% passband, and 50% phase, that will yield the same results as using the SoX command line of:
sox <infile> -b 16 <outfile> rate 44100 dither -s

One more question as I read someone post somewhere that when converting like this sometimes the audio can get clipped. Using --guard or something like that in SoX command line will prevent, rather warn about clipping and the volume can be reduced to prevent clipping.

Can I assume using the foobar SoX you won't get that warning? Seems like reason enough to use command line, or am I missing something?

Yes, that should give you the default same results as that command line. I'm not 100% sure about the options set "behind the scenes" in the plugin, but it should be using noise-shaped dither and clipping protection, AFAIK.

Awesome!!

Thanks so much
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-06 20:48:44
What I'm doing is: 1 MP3 & 2 FLAC
1 - 24/96 FLAC-->24/44.1WAV-->LAME MP3
2-                                            -->16/44.1 FLAC
If you cannot hear the differences of dither vs truncate (no dither), then it is wiser not to use dither when encoding to 16-bit flac since the noise used in dither is hard to encode which may yield bigger 16/44 flac files.

This is interesting...in my experience when actually comparing the two, the dithered FLAC files are almost always bigger. Not by very much, but this explains why. The greater the kHz the bigger the difference too.

Thank you

Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-07 08:08:52
I would not bother with +-10 percent of file size today. Personally, I would even stay at 48 kHz (not more). But I fully recognize arguments that say that 44.1 is enough because of what we can hear.

For sure Foobar is a convenient way to do conversions especially when you want to work with its playlists of files.

If you get to know the command line approach the SoX gives you more options for dither but as was already stated here the differences usually cannot be distinguished in ABX tests. There was a thread here this year where the sounds of highly amplified dither were posted, they can serve as a hint of how those "dither sounds" are applied. But in your position you need not to worry about it much and just choose dither and apply. Regarding audibility you'll be OK.


Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: KozmoNaut on 2016-12-07 08:25:20
It really doesn't matter, as we're talking about noise waaaay down in the signal.

So unless you're toying around with recordings that are skating along just barely above the noise floor, don't worry about it. And if that is the case, get some better recordings ;-)
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-07 14:44:07
There was a thread here this year where the sounds of highly amplified dither were posted, they can serve as a hint of how those "dither sounds" are applied.
Bad idea (read previous post).  When making decisions about noise shaping, it's an even worse idea because of equal loudness contours.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2016-12-07 14:45:14
Thank you for the input. I actually don't use foobar for most of my converting...I don't know why, it is pretty easy but I started with and still use Lame Frontend and FLAC frontend and then tag with mp3tag. I guess I just like the control and feel with those two programs even though I assume foobar has just as much control as those two.

The only thing I don't like about command line is I'm not good enough with the scripts to do batches of files...or I just don't know an easy way to do that (Windows here). When converting movie audio tracks using eac3to I don't really care cause I'm usually doing a single file at a time. But with musical audio it's almost always at least 10 files if not hundreds at a time.

I'd actually much prefer to use the SoX command line. It sounds as though you both prefer it. Even if I'm just just using the defaults like the script you mentioned above, I'd like to go that route. I do indeed like the control of command line.

Is there an easy way to script the code above for all .flac or .wav files in a folder? Playing around with sox.exe I couldn't figure it out.

Somewhere I think someone said make a .bat file and then drag and drop all the files I wanted to batch onto the .bat icon in explorer...but I couldn't figure out the code in that .bat file to make it output separate files with the same filename as the input files nor to a directory of my choice. I could get it to output all the input files (*.flac) into one giant outputted .wav

I need to learn how to loop

Thanks again for all the help.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: jumpingjackflash5 on 2016-12-07 18:34:09
Here I post an example of my batch file for conversion to 16/48. For 16/44.1 (which I use primarily for CDs) I would use the next command line (lower). Dither can be altered as desired. Also SoX filtering can be left at the default (95 passband, aliasing off) - if you omit the parameters -b -a (e.g. rate -v 48000/44100).
------
16/48
------
rem Example of how to do batch processing with SoX on MS-Windows.
rem
rem Place this file in the same folder as sox.exe (& rename it as appropriate).
rem You can then drag and drop a selection of files onto the batch file (or
rem onto a `short-cut' to it).
rem
rem In this example, the converted files end up in a folder called `converted',
rem but this, of course, can be changed, as can the parameters to the sox
rem command.

c:
cd %~dp0
mkdir "c:\music\Sox converted%~p1"
FOR %%A IN (%*) DO sox -V2 %%A -b 16 "c:\music\SoX converted%~p1%%~nxA" rate -v -b 88 48000 dither -f modified-e-weighted

---------
16/44.1
----------
FOR %%A IN (%*) DO sox -V2 %%A -b 16 "c:\music\SoX CD converted%~p1%%~nxA" rate -v  -b 92 -a 44100 dither
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: Cavaille on 2016-12-07 20:52:29
Well, I will suggest something else. While it is indeed good practice to dither you might consider not doing it. Most music contains a noise floor around -60 dB (give or take 10 dB), that is well above the limit of a 16 bit system. Not dithering will save time if you have a lot of music to convert. Not much... but a little.

Effectively, most music is self-dithering. With additional dithering you just add noise.

Not dithering might get audible on fade-ins and fade-outs. But you're not listening exclusively to them with extremely high gain, I assume :)
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: uselessladder on 2016-12-29 17:36:32
Hi,
I don't understand most of the technical aspects of this discussion and I've been doing these conversions by simply opening the 24-bit file in Audacity and exporting it as 16-bit. Is that acceptable? I can't tell any audible difference, but I haven't done a proper listening test.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: Apesbrain on 2016-12-29 20:06:43
^ Interesting question. Yes, that is a fine way to do it:
http://forum.audacityteam.org/viewtopic.php?f=48&t=73599
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2016-12-29 20:33:36
"That is called "quantize error", and if you don't do anything about it the quantize error produces harmonic distortion."

??

...except that quantization error doesn't exactly produce harmonic distortion, now does it?!?

Sigh.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: bmcelvan on 2017-07-25 14:16:23
Here I post an example of my batch file for conversion to 16/48. For 16/44.1 (which I use primarily for CDs) I would use the next command line (lower). Dither can be altered as desired. Also SoX filtering can be left at the default (95 passband, aliasing off) - if you omit the parameters -b -a (e.g. rate -v 48000/44100).
------
16/48
------
rem Example of how to do batch processing with SoX on MS-Windows.
rem
rem Place this file in the same folder as sox.exe (& rename it as appropriate).
rem You can then drag and drop a selection of files onto the batch file (or
rem onto a `short-cut' to it).
rem
rem In this example, the converted files end up in a folder called `converted',
rem but this, of course, can be changed, as can the parameters to the sox
rem command.

c:
cd %~dp0
mkdir "c:\music\Sox converted%~p1"
FOR %%A IN (%*) DO sox -V2 %%A -b 16 "c:\music\SoX converted%~p1%%~nxA" rate -v -b 88 48000 dither -f modified-e-weighted

---------
16/44.1
----------
FOR %%A IN (%*) DO sox -V2 %%A -b 16 "c:\music\SoX CD converted%~p1%%~nxA" rate -v  -b 92 -a 44100 dither
I just noticed this...I don't know how I missed it.

I wanted to say thank you very much...awesome stuff!!

Ben
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: Fairy on 2017-07-26 07:44:52
Convert 16 bit to 8 bit with and without dither. Choose the one you prefer (most likely the dithered version). Choose that setting for your conversion to 16 bit. The effect will however be a factor 256 smaller than the 16 to 8 bit conversion.
Title: Re: Should I dither? (Converting 24bit to 16bit FLAC)
Post by: greynol on 2017-07-26 11:57:50
...to the point that it is no longer audible and therefore completely irrelevant.