Thursday, June 24, 2010

My digital audio guide - SqueezeCenter modded!


This fourth part of my complete guide to digital audio covers modding SqueezeCenter so that I get the most quality out of my CDs.

One of the things that I really like about Logitech's SqueezeCenter is that it supports my favorite format right out the box.   I'm talking about Cue Sheets with FLAC audio.

However, I have two minor problems.  Since I store my audio CDs as perfect rips (without any modification), I have effectively (and intentionally) deferred the issue of handling pre-emphasis as well as HDCD decoding.  Good high-end DACs usually handle these (when paired with a CD transport), but squeezeboxes don't behave like a CD transport.  HDCD will work with a Squeezebox & DAC, but the preemphasis flag is always lost.  I don't use a DAC anymore, so I wanted a solution for both issues.

Since there have been bug (enhancement requests) covering these features forever, I got tired of waiting for someone else to do this.   There are already programs that handle these conversions (hdcd.exe and Sox), all that remained to be done was to plug them into SqueezeCenter's audio processing pipeline.  Fortunately, the software architect(s) and SlimDevices/Logitech made this pretty easy to do.  I'll show you how to install this mod so you too can have HDCD/Preemphasis decoding.

First, here is what the mod can do:

Features:
  • Processes audio data on-the-fly
  • Supports HDCD in either individual tracks or Cue Sheets (FLAC or MAC)
  • Applies De-emphasis (for Pre-emphasis in Cue Sheets)
  • Deemphasis is applied at 24-bit resolution
  • Should work with all Squeezeboxes (haven't tested the Transporter)
  • Softsqueeze/SqueezeSlave also work, but are limited to 16-bit
  • Supports transcoding down to MP3 (bit rate limited)
Software Installation

(You may have these installed, if you have followed my posts)
Next you will need my script and a conversion configuration file
Note: This software should work in non-Windows environments as well (Linux/Mac).  I've written the scripts to work in Linux and the HDCD executable will run under Wine.

Setup steps:
  1. Make sure convwrapper.pl and hdcd.exe are in your Audiotools folder.  Note the path to this folder, you will need it in a minute.
  2. Stop SqueezeCenter (right click on the Windows icon in the task tray)
  3. Move custom-convert.conf to your SqueezeCenter server directory.  This should be "C:\Program Files\Squeezebox\server".   However, the path may be slightly different based on the version you are running.  To be certain, make sure it is the same directory that contains the file "convert.conf". 
  4. Using your favorite text editor (I like pspad), edit custom-convert.conf.  Replace every instance of "c:\local\gdir\Audiotools\convwrapper.pl" with your path.  Save your changes.
  5. Re-Start SqueezeCenter
IMPORTANT TIP:  When you are copying / editing the file "custom-convert.conf" on Windows, make sure you always do so as an administrator (because it is contained in a system folder).   I found out the hard way that it is possible to (apparently) create two versions of a file with the same name (one as a regular user, and another as administrator).  Perhaps it is just me or the editor I was using.  Needless to say, this causes all kinds of weird problems.  If this happens to you, delete the file and start over.

That's it!

Now, how do you know it is working?

Whenever you play music that (might) contain either HDCD or has preemphasis applied, the script "convwrapper.pl" will run.   You can see this as an extra "perl" process running in Windows' task manager.

If the track in question has HDCD, you will also see an "hdcd" process.  However, this program doesn't stick around forever so it is best to check the task manager when the track first starts.  Likewise, when you are playing a track with preemphasis, you will see an extra "sox" process running.   Other than that, you can let your ears be the judge.

This modification is easy to undo, so you can perform some experiments yourself.

For the curious, how this mod works (skip this if you like):

First of all, let me say up front that I'm no expert on the internals of SqueezeCenter.  I've done a few mods, and I only know what I've been able to reverse engineer or read on their forums.  If there is detailed documentation about this, I'm not aware of where it is.  Any pointers would be appreciated

First, let's look at custom-convert.conf

This file contains SqueezeCenter rules for overriding the transcoding (format conversion).  If SqueezeCenter needs to translate a FLAC to MP3, it follows the rules in "convert.conf" and "custom-convert.conf".  Here is an example line from this file (for FLAC to FLAC transcoding):
  • flc flc transcode *
This line is followed by the actual audio transcoding pipeline.  All I did was insert my "wrapper" script after the initial decoding of the audio, but before the re-encoding.  There is a little trick involved here and you can read the comments in convwrapper.pl to learn more.

Note: Cue Sheets are always transcoded (squeezeboxes can play FLAC files natively, but not cue sheets with FLAC files).   Therefore, this FLAC-FLAC rule applies specifically whenever we play a cue/flac file on a squeezebox.

Each of the rules in custom-convert.conf represents different cases of transcoding that could involve HDCD or Preemphasis.  Feel free to add, modify, or delete these lines as you like.

One more thing.  While I added support for Monkey's Audio, it really doesn't work very well with Cue Sheets.  Monkey's Audio's command line decoder doesn't support seeking, so it won't allow you to skip tracks.   This makes Monkey's audio a pretty poor choice when using Cue Sheets in general.  I'm sure this could be fixed, but I prefer FLAC anyway.

Next, let's talk about convwrapper.pl:

This script expects to read uncompressed audio from its' input.  Normally, it would also write the audio to it's output.   Since the pipeline usually ends in sox, the script takes advantage of this by simply passing an extra command to sox to do the deemphasis.  This is why there is a missing "|" after convwrapper.pl's arguments.  The last sox process is actually launched by convwrapper.pl.

Convwrapper.pl tests it's input audio to see if it has HDCD.  If it does it will apply hdcd decoding prior to writing it's output.  Likewise, if the input is a cuesheet, convwrapper.pl will look for the string "FLAGS PRE" and will make sure deemphasis is applied.

References:


8 comments:

  1. I have two questions, and I should say up front that I may be in over my head with this:

    1. I can't locate the Audiotools folder (in XP or in Vista). Can you tell me where it is and how to see it? Maybe I need to log on as administrator in order to see it?

    2. I have used dBpoweramp to rip some HDCDs to flac files (one per song) at 24 bits. These play on the squeezebox but at lower volume. Does this accomplish the same thing as your method, except for the decreased volume? (so all I need do is turn it up)

    3. Do you know if your method works under the latest squeezebox server (7.6 I believe)?

    Thanks, John (ecajohn1@aol.com)

    ReplyDelete
  2. Yes I can count, I thought of a third question as I was typing!

    ReplyDelete
  3. Hi John,

    1. You create Audiotools yourself. It is a holding area for the tools / files needed above.

    2. HDCD lowers the volume by 6db, this is by design. And yes, dBpoweramp uses the same hdcd tool that I reference.

    3. Yes.

    ReplyDelete
  4. Thanks for your response George.

    I read up a bit on the HDCD process. As I understand it--The HDCD process adds 6db of dynamic range, and this pushes down the average volume by 6db. I'm not sure if the actual recording gains dynamic range in the process or if there is some other reason for decreasing the average volume.

    Playing 24 bit flac files ripped from HDCDs by dbpoweramp on squeezebox, the volume is lower than the same CD ripped on dbpoweramp without the HDCD DSP engaged. I understand now why this occurs, but I don't know why the volume is not bumped back up by the process unless it is because the dynamic range of the recording has been expanded, and the volume is left low because high volume spikes may occur because of expanded dynamic range (I don't think this is true based on limited listening to these files, but I could be wrong). It seems to me that the way I have been doing this may be faulty because the volume is not bumped back up by the process.

    Finally, here is my question: Does your method increase the gain at all after the HDCD process does its thing? Or, do you have to manually increase the volume on the amplifier?

    Thanks very much for your help,

    John

    ReplyDelete
  5. Very good question. As I understand it, HDCD implementations reduces the gain by 6db during decoding from 16-bit to 24-bit (20-bit actually, padded to 24-bit). CD players that implement HDCD decoding usually compensate for this by an analog bump of the gain by 6db (so you don't notice the difference). You can read more about HDCD on wikipedia as well as hydrogenaudio forums.

    I understand that you can't simply increase the decoded HDCD files digitally because you may introduce clipping.

    You might play with replay gain solutions, but again you have to be careful of digital clipping.

    I simply live with it. There is no real standard for absolute average levels of playback anyway.

    Enjoy.

    ReplyDelete
  6. I'm with you--I'll just turn up the volume on the amplifier. No sense in mucking up the file trying to increase the gain digitally, when the whole point is to enjoy improved sound.

    ReplyDelete
  7. Hi George,

    I am using option "decoding flacs on the server", and can't set up your tool properly. With settings below I heard just "white noise"

    flc pcm * *
    # F:{FILEnTIME=%f %t}T:{START=--skip=%t}U:{END=--until=%v}D:{RESAMPLE=-r %d}
    [flac] -dcs $START$ $END$ -- $FILE$ | perl d:\local\gdir\Audiotools\convwrapper.pl [sox] $FILEnTIME$ [sox] -q -t wav - -t raw -L -e signed -C 0 $RESAMPLE$ -

    Could you help me please

    ReplyDelete
  8. Hi Sajko,

    You are going from a flac to a wav (which I don't do). I also don't know what your output device is (and it may matter).

    While it might not make any sense to convert back into a flac after having gone to the trouble of decoding HDCD/applying emphasis, it might just work better in this case (my first recommendation). If you must have a wav output, I'd first start by debugging a simple flac to wav rule that doesn't involve my wrapper script. Once that is working, then make really small changes (and test them) until you can determine the problem (or get it working).

    Hope that helps.

    ReplyDelete

Copyright (c) 2010 CuttingTheBills.com. All Rights Reserved.