Thursday, October 12, 2017

Raspberry Pi - Audio Engine - Part 2

Now 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 be using  PicorePlayer3.22 as OS. 

The HW setup is described in Part 1 of this series.

The LogitechMediaServer (LMS) is basically configured as I laid out 
in the LMS configuration article.

Some words about the process:

 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 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 offers certain settings.

Note1: ABove screenshot needs slight modifcations 

           1. For Piano21 - Enable both options under "Simple Mixer Controls"
           2. For Piano21+Kali - Enable glb_mclk (using the Kali master clock for the DAC)
               in the "DToverlay parameter options" section.

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 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:600000.
     That means we look at a 20MBytes stream buffer and a 600MB 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%.

Below printout shows the settings for the IMO excellent Allo Piano 2.1 in Dual-Mono mode. (The first part you can apply to pretty much all HAT DACs!).

Note: Above image shows Alsa buffer at "16384", change this to "65536".

That'll be it.

Make sure you didn't miss my LogiTechMediaServer setting article. It's mandatory to have 
squeezelite and the server performing at best!