One way to fix this is to use sox to resample your Hi-Res FLAC files. This tutorial teaches the basics of sox and how to use it to resample FLAC files in Linux. Tips: if you are confused over the different audio formats, check out this guide to understand the differences between MP3, AAC, FLAC and many other formats.

What Is Sox and How Does Resampling Work?

At its core, sox is a command-line audio processing program. Unlike Audacity, it allows you to manipulate audio files straight from your terminal. This makes sox useful for those who want to make simple edits or automate a complex audio task. Resampling, on the other hand, is the process of using complex algorithms to transform a high fidelity signal to a lower one. This approach retains the quality of an audio track while reducing the amount of data that you store in your computer. Aside from that, resampling also allows you to play your Hi-Res FLAC files on lower-end devices. A Rockbox iPod Video, for example, will lag and stutter while playing a 24-bit audio file. Alternative: other than sox, you can also use flac2all to transcode FLAC files to other modern audio formats.

Resampling a Hi-Res FLAC File Using sox

Note: the steps below are for Ubuntu, but usage remains the same regardless of the Linux distribution you are using. The first step in resampling FLAC files is to install both the sox utility and its dependencies. Run the following command in Debian and Ubuntu: Check whether it is properly installed: sox –version. Find both the Bit Depth and the Sample Rate of your FLAC file by using the built-in file program to print these details in the terminal: In my case, my FLAC file has a bit depth of 24-bit and a sample rate of 96 kHz.

Finding the Right Resample Rate for sox

Find the right resample rate for your FLAC file. The general rule of thumb in resampling is that the target resample rate should be divisible to the original sample rate by 2 or 4. You should only resample a 192 kHz FLAC file to either 96 or 48 kHz to ensure the resampling algorithm can transform the original signal with as little distortion as possible.

Optimizing the Resampling in Your Hi-Res FLAC File

Once you know the right resample rate to use, you can run sox to resample your FLAC file. In my case, I am resampling a 96 kHz file, so I am running the following command:

The -b flag tells sox to set a new bit depth for the output file. For example, a value of 16 will set the new bit depth at 16-bit.On the other hand, the rate option tells sox to set a new sample rate for the output file.The -v flag forces sox to use the “Very High Quality” resampling algorithm.The -L flag also forces sox to use a “Linear Phase” response during resampling. This is a filter that attempts to neutralize any “signal echo” in the FLAC file.Lastly, the dither option generates a small amount of noise across the whole track. This serves as a mask that will hide any imperfections in the resampling process.

Automating the Resampling Process

While it is doable to use sox on a per-file basis, it is also possible to automate the entire process using the shell. (Check out the beginner’s guide to shell scripting.) This is useful if you intend to resample an entire album of Hi-Res FLAC tracks. One of the quickest ways to automate the resampling process is to use a Bash for loop. For example, you can run the following lines of code to resample an entire folder of FLAC files: The first command will create the output folder for the new FLAC files as well as change the current working directory. The second command will loop through every file in the current folder and resample it using sox. Image credit: Unsplash. All alterations and screenshots by Ramces Red. To fix the missing system library, run the following command: sudo apt install libsox-fmt-all. Fixing the missing compiler flag will require you to uninstall the current sox package and compile it from source. Despite this, it is still possible to tell sox to compensate for possible clipping during resampling. To do this, add the -G flag to your sox command: sox -S sample.flac -G -b 16 resample.flac rate -v -L 48000 dither.