Thursday, October 12, 2017

Raspberry Pi - The Audio Engine - Part 3 - squeezelite and DAC settings

In Part 3 of this series I'd like to share some lines about the parameter settings of squeezelite.

squeezelite comes with numerous options that can change it's performance
as well as its functionality.

For this exercise I'll obviously be using  piCorePlayer once more. 

The LogitechMediaServer (LMS) setup I basically covered in the LMS configuration article.

Some words about the configuration process while being inside the respective masks:

 1. In any case, set up your Audio Output = sounddevice first and save your settings
     The OS usually has to reboot to enable the newly configured audio device!

 2. Then you'll be able to set the "Audiocard control" settings.
     These are the "Alsamixer settings". Depending of the sounddevice driver
     you'll be allowed to change certain functions on your sounddevice.
     Usually it's a good idea to have a look at that! These settings will
     persist. squeezelite needs to be restarted after running certain alsamixer settings!  
     Just confirm if pCP asks you to restart squeezelite after you've saved the new settings.

3. Now you enter the squeezelite settings and ""save"" !!! them.
    If this is done you'll be asked to confirm a squeezelite restart.

4.  Reboot your device and check if all settings are properly configured! 

I. AudioCard Control

The Audio Card control settings should be configured for each and every audio device.  
Depending on the device and its driver you'll have more or less parameters to play around with.

E.g. The  TI PCM51xx dac as used on the Allo Piano2.1 and the Allo driver offer certain settings. The pCP team has made them available to us via GUI.

Below printout shows my preferred settings for the IMO excellent Allo Piano 2.1 in Dual-Mono mode in conjunction with the Allo Kali I2S reclocker

Make sure you disable the "Pi Builtin Audio".

Enable "glb_mclk" (using the Kali master clock for Piano21) must be used
            with the Kali+Piano21 only! 

Note2: Make sure all your settings are saved properly!
            You better reboot the RPI and verify that all settings are as
            you've selected them! 

II. Squeezelite parameters

1. Name
    Choose whatever you like (1 string - alphanumeric - no spaces)

2. Output setting
    We have disabled the RPI internal Audio device under I.
    Therefore only one audio device is active on the system.
    Simply enter the listed string.

3. Alsa setting

    The chosen buffer value of  "65536" (=2^16) bits will be divided into "4" chunks (=periods)
    For USB DACs you might want to try "160" instead.
    The 3rd field - if empty - lets Alsa decide what bitdepth towards the DAC to choose. 
    Most modern dacs and HAT dacs run usually 32bit.
    MMAP allows squeezelite to access the device memory directly

4. Buffer size settings

    These shouldn't be mixed up with the Alsa buffer settings.

     There are two buffers we're looking at.
     1. The stream buffer
     2. The output buffer (output from squeezelite to Alsa!)

     squeezelite puts the received audio data into the stream buffer first.
     The internal processing stages e.g. flac-pcm conversion, resampling or
     volume control will 
then be executed and  the result gets stored in the output buffer.
     Data will be stored at 32bit in that output buffer.
     If you look at below setup proposal, you'll see 20000:500000.
     That means we look at a 20MBytes stream buffer and a 500MB output buffer.
     What happens is that squeezelite reads and processes the entire file
     as soon as you push the start button. You'll see a high peak load
     in the first couple of seconds of playback and then the fully processed file
     is played back from a RAM buffer. A typical CPU load will be below 1%.

5. Restrict codec setting

    The order of codecs as listed in this field, defines the priority of conversion rules
    applied by the LMS server.
    Since I usually recommend to run PCM streams, such a PCM rule will be
    first choice for this client 
if more then one rules are active on the server for the same
    input format. Got it ?? OK. Once more.

As you can see 3 rules are active. Without using this "Restrict code setting" field
a flac-file would be send as "FLAC-Native". That's hardcoded inside squeezelite.
You'd never know what's hardcoded in whatever client. By using this field you 

can control these priorities without having to disable any rule. You might want to run 
mp3 towards another wireless client. Then just change the order of codecs listed 
in this field on that client. 6. Various input

    1. Read stream parameter from PCM header

     Basically "-W" allows server based resampling and still sending out PCM streams.
     Since I use (and recommend) server based 352k8/384k resampling to PCM for the
     Piano2.1/Boss. I have written another article of how to accomplish the server based
     upsampling. I'm not sure why this option isn't enabled by default.

     2. Use HW/DAC internal volume control

     Basically "-V Master" controls the "Master" volume control as being offered by the driver.
     The name "Master" is freely chosen by the designer who wrote the driver.
     For the Allo Boss it would be "-V Digital".
     I do this to avoid having two digital volume controls in the loop - you never know.


      Note: The "Alsa setting" is "65536" = 2^16.
                For USB DACs you better use e.g. "160" (ms).



That'll be it.

Make sure you didn't miss my LogiTechMediaServer setting article. There are certain overlaps and dependencies (e.g. under "Advanced Settings - File Types")

It's mandatory for a complex system to have all parts involved aligned and under control. 
This way and only this way you'll end up with a great performing audio system!



  1. Replies
    1. Please, send my your e-mail - Please use the new contact form!

    2. Hi Klaus,

      What exactly is in the Binary ? It will work with rp2+Kali+AudioGD Hdmi output ?



  2. thanks for the write-up. i set alsa buffer as 44100 bytes (or multiples) for 16/44.1 material with very good results as per this article i am curious to know how you ended with 16384.

  3. That makes an impressive change! Thank you!!!