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: Downsampling 192/96 to 48 kHz - best SoX setting? (Read 3832 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Downsampling 192/96 to 48 kHz - best SoX setting?

Hi guys,

I will downsample some parts of my library. Mostly this is about 96kHz. Music of lower importance for me. If I do it I want to do it right.

Passband, Phase Response, Aliasing - I have not much understanding here. What would be reasonable settings for downsampling?

My current settings for downsampling multipliers of 48 are as in the screenshot.

Thank you

X

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #1
Does this guard against clipping?
Potential problem arising: you don't want volume changes across track transitions.

Also, if you want to save space:
I would be surprised if all your 192 tracks are 16 bits only. You can decimate off quite a lot of noise in the lower bits, and guard against clipping at the same time by reducing volume.
Relevant thread: https://hydrogenaud.io/index.php/topic,125718.25.html

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #2
Thank you, oh, so many complications (beyond the audibility threshold though). I was expecting that :-D
Very interesting thread you posted. I am coming from the exact same perspective as Gurubulez there.

BTW I looked over my files. Source will always be stereo 96/24, no 16 bit source. Depending on my feelings, I will convert them to Redbook or to 24/48. 24 bits are quite heavy on the file size.

I have seen quite some spectograms of hires files. 96 to 192 is just a waste, there usually wasn't anything. But what I saw was often regular audio very naturally going up until ~30 kHz.

Thoughts.

1. 64 kHz would hence by my peace of mind resolution. Plus maybe 18-20 bit depth. But that's not standard. As for resolution, someone posted the idea to lowpass below 32k and leave the file on 96khz. That's a good idea. Now I'll look how to filter. I remember I tried SoX Lowpass but it was capped at 25khz.

1b. If there is no filter available to filter at ~30kHz: Would it make harm to the source, if I have two resamplers in the converter chain like this? a) SoX downsampling to 64 (so it will neatly filter and cut everything above 32khz per channel) and then b) Upsampling to 92 kHz - just in order to have a compatible file.

2. -3db safety margin. OK, with just a simple volume changing plugin (there is one)? Recommendation? foo_dsp_amp? It somewhat does not feel good, changing the source file in a way I don't want it.

3. There's some advanced ssrc resampler, need to have a look again. Or just use SoX... hmmm.

4. How do people reduce bit depth, eg. to 20? Is that a flac option? fb2k GUI has 8,16,24... It's probably bringing compatibility issues, but I'm not sure, I use my flacs in fb2k exclusively anyway.
   EDIT: --bps=n in FLAC command line

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #3
Here's a spectogram reflecting some peace of mind. 64 khz flac file. Something I also may consider.
What I don't understand is, how people are able to mess with unusual bps. If I tell flac to use --bps=18, it drops an error.

X

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #4
SoX can do volume change, but I don't see anything in that window you posted.
-3 dB safety margin removes half a bit resolution. If you want to go say 18 bits it's gonna be 1.5 bits more than CDDA.

64 kHz is maybe the only thing between 48 and 88.2 that "anything" supports, but not much - even then you might have to resample on-the-fly upon playback. If you can ABX a fast on-the-fly upsampler 64 --> 96 (or --> 88.2) against a time-consuming one, then you can post it here for a discussions ;)

4. How do people reduce bit depth, eg. to 20? Is that a flac option? fb2k GUI has 8,16,24... It's probably bringing compatibility issues, but I'm not sure, I use my flacs in fb2k exclusively anyway.
   EDIT: --bps=n in FLAC command line
That's wrong. That's for when you input from a raw headerless PCM file, then you have to specify what it is in there, because the bit stream itself doesn't say when the bits of one sample are done, and the next begins.

WavPack can do that, actually. For 20 bits, use --pre-quantize=20

.flac files will typically become 24 bits with an insignificant penalty of a few bytes per second. It is possible to specify a .wav or .aiff file to be "20" valid bits, but I actually don't know how to "enforce" it.



Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #6
Thoughts.

1. 64 kHz would hence by my peace of mind resolution. Plus maybe 18-20 bit depth. But that's not standard. As for resolution, someone posted the idea to lowpass below 32k and leave the file on 96khz. That's a good idea. Now I'll look how to filter. I remember I tried SoX Lowpass but it was capped at 25khz.

2. -3db safety margin. OK, with just a simple volume changing plugin (there is one)? Recommendation? foo_dsp_amp? It somewhat does not feel good, changing the source file in a way I don't want it.

4. How do people reduce bit depth, eg. to 20? Is that a flac option? fb2k GUI has 8,16,24... It's probably bringing compatibility issues, but I'm not sure, I use my flacs in fb2k exclusively anyway.
   EDIT: --bps=n in FLAC command line
All that is possible through command line:
Code: [Select]
sox INPUT -b24 OUTPUT gain -3 rate 96k sinc -t 4k -32k dither -p20
  • gain -3 -- reduce volume by 3dB
  • rate 96k -- convert to 96 kHz sampling rate (optional)
  • sinc -t 4k -32k -- lowpass at 32 kHz with 4 kHz transition band (so starts at 30 kHz)
  • dither -p20 -- apply 20-bit dither, less significant bits are zeroed

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #7
Can this (i.e. SoX treatment plus flac encoding) somewhat be achieved in one run in fb2k converter? Batch file needed?
I also found https://foobar.hyv.fi/?view=foo_dsp_dither which can limit bits per sample. I wonder what's best - Before or after resampling?

Instead of lowering volume -3db as for clipping security, what do you guys think about replaygain_alternative? Would be at the end of the converter chain, before dithering.
I.e. SoXResample -> Replaygain -> Smart Dither

X

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #8
My current related converter presets with their chain, in order.

a) Low: Create 44.1/16 flac.
- SoX: SampleRate 44100, Best quality, Passband 95, Aliasing off, Phase response 50
- Replaygain(Alternative), clipping only, max 0dbfs, compress peaks, rescan everything

b) Medium: Create 48/19 flac (24 bps reported).
- SoX: SampleRate 48000, Best quality, Passband 95, Aliasing off, Phase response 50
- Replaygain(Alternative), clipping only, max 0dbfs, compress peaks, rescan everything
- SmartDither, Target bit depth 19, Amount of dither 1

c) Higher: Create 64/20 flac (24 bps reported).
- SoX: SampleRate 64000, Best quality, Passband 95, Aliasing off, Phase response 50
- Replaygain(Alternative), clipping only, max 0dbfs, compress peaks, rescan everything
- SmartDither, Target bit depth 20, Amount of dither 1

In the classical + orchestral realm, say if a 96 kHz file has 2200kbps, then the resulting 44/16 may be at 600 kbps, the 48/19 at ~800, the 64/20 somewhere at 1200 kbps.

My thought as for the Replaygain clipping compression is, it may affect just a few samples normally - and if plugin does its thing, it may be inaudible. I prefered this over lowering the volume.

I hope the converter chain order is reasonable.

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #9
I may use mda_dither instead of SmartDither.

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #10
I've had another idea. I search the very loud albums and only for those I start the conversion with a very tiny (-0.2 db) amplification (foo_dsp_amp). For my testing set, this brought all loudest files into the [0.99..]1 area. Also now I'm displaying a marker in my ColumnsUI "$ifgreater(%__replaygain_track_peak%,0.98,..)" to get some awareness there.

Code: [Select]
(%SAMPLERATE% IS 96000) AND (%__replaygain_album_peak% GREATER 0.98)

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #11
$ifgreater cannot compare float, this is how I display loud RG values. Dots if normal, values if album loud:

Code: [Select]
$if(%__replaygain_track_peak%,$ifgreater($replace($left(%__replaygain_album_peak%,4),'.',),97,$left(%__replaygain_track_peak%,4),●),●)

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #12
when resampling up like 44100hz->48000hz and passband is 0.95 it means over 44100/2*0.95(=20948hz) get distirtion and can also make alias echoes under that 20948hz. i am not sure how calculation goes when resampling down in ur case maybe like this: 48000/2*0.95(=22800hz)  and samples over that can make alias and will be distorted
In metal high tones that can not even hear can be important for feeling. tones from other side. the dark side. use the bits Luke

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #13
pls correct me if i was wrong
In metal high tones that can not even hear can be important for feeling. tones from other side. the dark side. use the bits Luke

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #14
For the completeness, and maybe there's remarks, room for improvement: I want to summarize what I ended up with. All conversions are done and more importantly, I have a consistent strategy now for the future. I don't mention the 176.4/88.2 resolutions now. You know they exist. The following is all about downsampling.

1. I downsample 192 kHz material in any case.
2. I keep audio material only at 96 kHz if it is of very high value for me. This is like 15 CDs.
3a. If something is "rather important" for me, I create a 64 kHz file. This is my "peace of mind high quality setting".
3b. if something is less important, I put bits per sample down from 24 to ~20-22 (word length in mda dither), which significantly changes file size. I add a tag, so that change can be seen in fb2k.
4. If something is "rather not too important" :D, I aim for 48/24. In general, lossy output for target devices is all encoded to 48/24 because typically there's native support and no resampling on the fly necessary. I changed my strategy and resample also the 44.1 multipliers down to 48.

As mentioned, "Importance" is one factor for decision making on the target resolution.
The other factor the source audio. I always look into the spectogram (start wave editor with a quick click in fb2k, via foo_run). So if there's just shaped noise (eg from DSD transfers), if there is a big nothing, thats not needed. If frequencies end at 20-22k there's no need for 64/92k audio files. My experience: the majority of hires files, frequencies bleed into the 30k range, but often not much more. Hence 64k is perfectly fine.

Foobar 2000 converter settings:
Code: [Select]
1. Resampler (SoX) / 48000 o. 64000 / Best / Passband 95 / PhaseRes 50 / [ ] Aliasing
2. mda Dither / HP Triangular PDF / WordLen 20-24 / DitherAmp 0.8 / DCTrim 0 / Zoom 0

Potential clipping: I decide if volume needs to be decreased beforehand. Source material is replaygained, so I see what's necessary. For lowering 3dB or more I have different presets using foo_amplify.
For subtle/automatic gain changing I use Replaygain (Alternative), "Only prevent clipping album, -2 dbfs, reduce gain".

FLACs have some padding space for art.
Code: [Select]
-s --ignore-chunk-sizes --padding=393216 -7 - -o %d

Let me repeat this is about keeping a good source file, technically as good as possible and to not waste space. House keeping. We're not talking about audible differences, i.e. TOS realms.

Others please judge Passband, aliasing, Dither amplifier, I have not much knowledge in that field. I use dithering a) for the nulling of least significant bits and (if not) b) because "it is said" that one should add dithering on downsampling because of whatever (theoretical?) artifacts..

@123jippo My understand was, Passband 95 is a LPF at 48k * 0.5 * 0.95, as you say. And to compensate for some potential audible problems, dithering is necessary. Which adds noise at inaudible frequencies.

BTW, 64 kHz for playback in fb2k (I don't use the files anywhere else). This is a rather unusual resolution. There's some rare cases, mostly on changing of files while Playback, where there's silence. I need to stop and restart playback. IDK if it's related to my soundcard, whatever. Not seeing a problem here. Small issue.

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #15
Squeller :can be like that also. but from somewhere i did get idea that dithering only needed when redusing bit depth. aliasing is related on resampling. i no pro so maybe remember incorrect...
In metal high tones that can not even hear can be important for feeling. tones from other side. the dark side. use the bits Luke

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #16
Squeller :can be like that also. but from somewhere i did get idea that dithering only needed when redusing bit depth. aliasing is related on resampling. i no pro so maybe remember incorrect...
Great, you're right! I confused it. So yeah, no dithering necessary when I only do resampling.

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #17
SoX and others resample at their internal precision. Since this is above 24bit dither is applied until you choose to disable it even when the resulting file is 24bit.
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

 

Re: Downsampling 192/96 to 48 kHz - best SoX setting?

Reply #18
when resampling up ... and can also make alias echoes under that 20948hz.
Aliasing can happen when downsampling but not when upsampling. With upsampling you get "images" which need to be filtered out. Images are mirror copies of the original range that appear above the original range. For example, in the process of upsampling 48k to 96k a mirror copy of 0-24k band appears in 24-48k band. If not sufficiently filtered out then those images can potentially cause IMD upstream (amp, speakers). But there is no aliasing.

i am not sure how calculation goes when resampling down in ur case maybe like this: 48000/2*0.95(=22800hz)  and samples over that can make alias and will be distorted
The calculation always applies to the smaller frequency.

Below is an example of white noise:
  • generated at 44.1k and upsampled to 192k
  • generated at 192k and downsapled to 44.1k
using SoX rate command with its default settings. As you can see the transition band is about 21k to 22k in both cases.
(I mean, I'm only assuming that it's the same when using the foobar component)
X
X