Transferring CDs to FLAC on MacOS moocher style

The Moocher is a music collector with a growing CD and record collection. In this article, the moocher describes how he transfers CD to FLAC to play using Roon Labs Roon Player. We’ll look at the motivation behind FLAC, the tools used to turn a CD into FLAC encoded tracks, and how to get the tools.

References

  1. https://xiph.org/flac/
  2. https://xiph.org/flac/license.html
  3. https://brew.sh
  4. https://tmkk.undo.jp/xld/index_e.html
  5. https://www.hdtracks.com/
  6. https://livesnarky.com/
  7. https://support.apple.com/kb/PH25389?viewlocale=en_US&locale=en_US

About FLAC

FLAC is the free (as in liberty) audio lossless codec developed by the XIPH Foundation, a Greek pun on HiFi. The developers have a deep commitment to the digital storage and playback of music for enjoyment and for commerce. Their work is an response to  the Franhoffer Institute’s patents and license fees surrounding the original MPEG work occurring at several university research institutes and in industry.

To legally use FLAC required a license from the Franhoffer Institute and payment of royalties. The license terms made it a dodgy act to encode music in MP3 format or to play that music without the proper licenses. MacOS and Windows included these as Apple and Microsoft purchased appropriate licenses to use MP3 technology in their products. To dodge royalties both companies developed their own proprietary codecs that they held close to the vest. So they were no better than Franhoffer.

XIPH Foundation set out to break the stranglehold on digital media by developing public domain multi-media codecs that may be freely implemented and used without cost or license obligation. XIPH Foundation licenses its products under BSD and GNU Public Licenses. These licenses allow free use of the reference implementation which is available in source form and require that source code be available and that derivative source code use the same license as the original.

The algorithm specifications are also available permitting tailored implementations of FLAC and Vorbis that use custom hardware features such as the processor’s vector instructions or video hardware via OpenCL.

FLAC is “lossless”. The encoder removes redundant information and encodes what is left in a form that recovers the original audio file bit for bit (bit-perfect). There is literally no difference between the original bit stream and the reconstructed bit stream. When you listen to a FLAC playback, you’re listening to the original master bit stream.

FLAC for Playback

Apple has been slow to embrace FLAC but has reacted to FLAC by making Apple Lossless Audio Codec open source under a license similar to that for Darwin, the Apple version of Free BSD. To use FLAC on MACOS requires a third-party product. The ones I use are Roon for playback and XLD for encoding. Roon just knows what to do.

I put my FLAC files in /Volumes/FreeNAS_Media/Users/Dave/Music which is CIFS shared with Guest access permissions from my FreeNAS FreeBSD-based media server. My old Mac Mini now out of software support runs Ubuntu 18-04 LTS and Roon Server to allow all my various playback contraptions to play my music.

Trey is setup to have RW access to the media share permitting its use to maintain audio, video, and photo libraries on the share. My iTunes library, photos app-library, and Capture One libraries are on this device. My Roon server and Plex server have shared read access to the media library allowing them to serve media and I can use either iTunes or Plex to maintain the medial on my iThings.

Roon comes with a version of FLAC that is a part of its tree. This is the one I use for playback. It is in /opt/Roon over on the Mac Mini. Roon has sweated this version for correctness and performance. It runs identically in a FreeBSD virtual environment, in Ubuntu, and on all Roon Server supporting platforms including MacOS and Win10.

FLAC for Encoding on MacOS

I have a collection of commercial FLAC tracks, I purchased my first FLAC tracks from HDTRACKS. More recently, I have purchased several live show recordings from Snarky Puppy, a little 18 piece post bop jazz big band. At this point, I own most of their CD catalog plus selected live shows from each year that they have been offering them.

Until this week, I used iTunes ALAC to encode CD’s in Apple Lossless Advanced Codec for playback. Past comparison of ALAC and FLAC media convinced me that both yielded bit perfect reproductions of the original.

After hearing all the nice Cat Stevens HDTracks albums and Snarky Puppy live shows, I made the decision to switch to FLAC for locally encoding music. A web search quickly located XLD and Reference 4. I downloaded the XLD disk image and quickly discovered it was 32-bit and would stop working when Mohave was installed (real soon now). So, what to do?

Homebrew Package Manager

Some time ago I became aware of HomeBrew package manager for MacOS. It manages Free Open Source software and has the ability to install in binary form or in source form and run a build much like Fink or Ports but better.

HomeBrew is an independent go using Ruby and MySQL, the current MacOS versions so you don’t have to FRIG-AROUND with some version newer than that in MacOS supported version but older than the project current stable version, a typical failing of Fink and Ports. So I installed home-brew per the instructions and ran brew install xld in a shell. XLD installed in /usr/local with the xld.app dropped into Applications. The end result launches in the normal MacOS way, just double click or launch via Siri and Spotlight.

The Brew project is similar to Fink and Ports in that there is a package maintainer who does the work needed for the package to compile and link and does the work needed to keep the package building when Apple changes something or new dependences are added in the upstream. That installation of XLD is trivial is a tribute to its Japanese developer and the  brew package maintainer.

Brew will run down the package, install all its dependences and install the specified package. The HomeBrew website maintains a list of supported packages which included XLD.

Changing the Default CD application

Open MacOS Preferences. Select the CD & DVD pane. Change the option for When you insert a music CD from Open iTunes to Open other app and select XLD.app. (when you make the switch , the app browser will open).

Review XLD Preferences

Once XLD is installed, launch it and review its preferences.

General

Select the output format here. Note MP3, ALAC, DSD, and FLAC among others are available.

Set the output directory here. This is the same for all rips so I have one called New Disk. Tracks are dropped here. I make an Artist folder if needed and an album folder and move the tracks after the rip is finished.

There is an option to use a temporary folder with tracks moved to the destination on completion.

You can pick the character set used for output.

You can add the tracks to the iTunes Library or to a playlist

There are options to prepend a byte order mark (off) and to check for XLD updates (on).

File Naming

There are options for custom file naming, options for action to take when an output file is already present (rename, skip, or overwrite), and the directory path separator.

Batch Runs

XLD can work from hard disk also. This set of options deals with directory recursion, treatment of multi-track files that have an embedded cue sheet, and what to do with the input file after conversion (keep or delete).

CD Database

Sets the CD catalog database to use for disk and track identification.

Metadata

Sets the option for dealing with track data, album artwork, etc. These can be left set to the defaults.

CD Ripping

These parameters determine the behavior of the CD reading process including use of error correction, retries, log file writing, creation of a cue sheet. Single or multiple output files, automatically reading a mounted disk, automatically starting the rip,  ejecting disk on completion, and exiting XLD on completion. The defaults generally work

Again, it is to your advantage to use error correction. The transfer may take a bit longer but you’ll get a transfer if it is at all possible.

Adding a CD to your Library with XLD

To encode a CD, mount it. In the CD drive and send iTunes away. In XLD file menu, pick Open Audio CD. XLD will open the CD and look up the track info and correctly encoded hashes. Using preferences and dialog options tell XLD how to encode the file, the container type to use (m4a is good as is ogg for Roon), and the place to put the file.

Note that you will have to make a directory for the artist and the album by hand and select the newly created album directory. XLD will encode the file, hash the output, and compare the new hash with the reference hash to verify that each track was correctly encoded.

XLD supports the following encodings

  • WAV
  • AIFF
  • PCM little-endian
  • PCM big-endian
  • Wave64
  • Apple Lossless Audio Codec
  • Direct Stream Digital
  • Ogg Vorbis
  • LAME MP3

CD encoding has the option to use CD forward error correction. The Red Book standard includes provisions for forward error correction that allow a CD reader to recover data from scratched  or otherwise abused CDs. The error correction uses redundant encoding techniques to reconstruct the defective bits. Use of error correction may be a little slower as the redundant bits have to be read and used in the reconstruction. If error recovery is successful, the damaged bit will be there. If not, there will be ticks and pops as the encoder substitutes zeros for the missing bit.

XLD uses AccurateRip.DB to confirm that the track was correctly ripped. it does this by calculating the hash of the converted track and comparing it with the track’s known correct hash. If the two are different, the track was not read correctly and parts are missing or otherwise back.

XLD also has an option to automatically add the track to iTunes library. I suspect it does this by putting the tracks in the Automatically Add to iTunes folder and letting iTunes do the work on its next launch.

XLD does not fetch cover art. Roon will do that on its own and add it to the Roon library.

Playing a FLAC CD in Roon

After a bit (whatever library poll interval you set) Roon will discover the new disk and add it to the catalog. Newly added disks will appear as additions in Overview. If you already have a title, you may have to search for and select the title, display at versions, and make the local FLAC version the primary version. That will make it appear in the Overview as a new album. Then, you can select an play the FLAC version in the normal Roon way.

Updating HomeBrew

Similar to Apt and Yum, brew update fetches the latest package catalog. Once the catalog has been updated, brew upgrade installs the latest packages To find out what will be upgraded, run the command brew outdated. To keep a package at the current version, run command brew pin <formula> where <formula> is the package name to be withheld from upgrading. The command brew unpin <formula> undoes the pinning.