Script to convert FLAC files using Shibatch Sample Rate Converter (SSRC) while preserving meta data

When using your PC as a high end audiophile transport device for delevering digital audio to an external DA-converter as explained in How to turn Music Player Daemon (mpd) into an audiophile music player, one has to make sure that the audio files are in a suitable audio format for the DAC. Consult the Background section below to determine which formats are suitable.

The flac-src-shibatch script will take a directory containing digital audio files, and convert it to a chosen bitdepth and sample rate using the not-too-bad Shibatch sample rate converter in “twopass non-fast mode” while preserving the flac metadata stored in the original files. It will put the original files in a tar ball for future usage.


  1. Install SSRC: See Shibatch SSRC Packages for Debian and Ubuntu
  2. Install flac and sox*:
    sudo apt-get install flax sox
  3. Download and unpack the source for the script:
    wget -O


Ad *: Although sox can be used as an audio backend and sample rate and format converter, in this scenario we only install it for obtaining the convenient soxi file analyzer.


The script resamples and replaces the original files in the directory and makes a tar ball containing the original files:

cd flac-src-shibatch-master
./convert-flac $sourcedir

Where $sourcedir is a directory containing high resolution tagged flac files.


The designer of my excellent Pink Faun 3.24 USB DAC, fitted its DAC with a Tenor USB chip and limited the maximum rate to that of USB Audio Class 1 (24bit / 96KHz) to make sure alle available operating systems can use the DAC as an audio device without having to install additional drivers.

However, when buying audio at HD Tracks  or Channel Classics, I want to get the best format available; currently that would be 24bit/176KHz or 24bit/192KHz. After buying and downloading the files I use Musicbrainz Picard to tag and rename the original files. If necessary I create the Musicbrainz entries myself. I then convert (downsample and convert) the files using my script to 24bit/96KHz when they have a sample rate which is higher than 96KHz. Files with lower sample rates are to be left alone.

To determine which formats are natively accepted by your USB DAC, and how it actually behaves when feeding it a certain format, have a look at What digital audio format (bit depth and sample rate) does your alsa sound card support and what does it actually use?

The resulting quality

The quality of the resulting file depends on a number of factors. The most important factor is the ratio between the original and the desired samplerate.

For instance, when the source file is in a multitude of fs = 48KHz, eg. (fs*4 =) 192KHz or (fs*8 =) 384KHz, the conversion in my case is a matter of simple calculation; leave out each nnd sample, where n is the multiplier devided by two (fs*2 = 96KHz). This effectively makes the audio signal more course because the time between samples will grow with n. Furthermore, the avaliable frequency band will be narrowed (divied by n), following the Nyquist-Shannon theorem (fs/2 – width needed for the lowpass filter). For example a 192KHz sample signal leaves room for a (theoretical) frequency band of <96KHz while the downsampled 96Khz sample will be limited to <48KHz. However, there will be no further interpretation of the audio like in the cases below.

For formats based on fs=44.1KHz,  like (fs * 2 = ) 88.2KHz and (fs * 4 = ) 176.4KHz, I need to let shibatch interpret the source and calculate a new file based on its internal algorithms, a Finit impluse response filter (FIR) applied through Fast Fourier Transforms (FFT). Furthermore, shibatch can be told to apply dithering when desired. This of course means that your milage may vary, depending on the source material. It can be rewarding to try different parameters while listening to the resulting file(s).

The scripts is available for downloading, sharing and modification at

3 thoughts on “Script to convert FLAC files using Shibatch Sample Rate Converter (SSRC) while preserving meta data

  1. First: Great work and very informative!
    I will test your scripts on Archlinux.

    Currently I am using:
    MPD->ALSA/plughw->Fiio DAC (32bit / 192KHz)
    My dac is always displaying the same sample rate and bit depth than the original file if lower => I guess then my chain is not doing upscaling.
    If file is higher quality, down scaling seems to happen to max capacity (32bit / 192KHz).
    In my setup I am confident that Pulseaudio is by-passed, hardware is used in exclusive mode by alsa.

    From your experience, if I do not want to pre-convert all my library to one setting, is ALSA/plughw the closest to original bitrate/less harmful way?
    My proc should be enough so on the fly conversion is not a problem in my setup.


    1. Hi Cyril,

      Thanks for your compliment and glad you find the article and script(s) helpful.

      About your setup; it’s not about whether you have enough processing power in your playback computer, although more activity could hurt audio quality. Bit-perfect playback is about not altering your music files at all. So no up- or down (re)sampling, no DSP, etc.

      With the one-liner below it’s should be rather easy to check what your computer is actually sending to your DAC:

      watch cat "$(alsa-capabilities -l usb -s 2>&1 | grep monitor | awk '{print $5}')"

      Next play some files of different sample rates and bit depths; the output of the command above should reflect those changes.

      But as you seem to use a virtual plughw alsa interface and not a real hardware device ('hw:x,y'); chances are you will not see anything changed because you've instructed mpd do perform the resampling on the fly.

      Good luck,

Leave a Reply

Your email address will not be published. Required fields are marked *