Saturday, January 20, 2018

RaspBerry Pi - The Audio Engine - Part 5 - Custom squeezelite

This is not the first post of this series. I strongly recommend to start @ Part1

Most of the project is done by now. If you're still looking for more, there is more. ;)

Advise
Perhaps you should wait for a week trying this measure.

The result of this exercise might not be that earth shattering as you'd expect it to be.
I'd recommend to get used to the performance of your current pCP setup and then you go ahead with this measure. 




What can still be done !?!?

There are two areas that still can be addressed and customized. 

1. The kernel
2. The squeezelite binary




1. The kernel is very difficult to customize under piCorePlayer.
I used to provide different customized kernels incl. a realtime kernel to the Moode project. 
Doing that for piCorePlayer is much more difficult.
I. I'm not in charge. II. TinyCore Linux is a pretty complex system.
No wonder that pCP provides a 2nd image for the 
advanced audio kernel version.
And III. Paul has it pretty well under control. I am in contact with the pCP folks from to time though. I do give feedback or input once in while.

I'd say we put the kernel aside for the time being.

2. Let's have a look at a manageable subject. The squeezelite binary.

What we can do is making the squeezelite binary running a bit more efficient. 

More efficient !?!? Yep. I hear you.

Beside coding quality and efficient source code, there are different items having an impact 
on the efficiency of the resulting binary.

1. the compiler (even the compiler version matters)
2. the compiling options (generic vs. HW specific)
3. static vs dynamic linking of used libraries
4. features and size
5. debugging options


We gonna look at 2. and 4. during this exercise. 

As an example, I measured 10-20% performance difference just by changing compiler options on the widely used linpack benchmarking tool. Basically the benchmark tool itself were depending on the compiler options for that specific hardware and gcc version.
What does that mean? If you look at any benchmark results and you don't know the benchmark tool compiler options and the gcc version the benchmark results are highly questionable!

Let's go on.

1. We'll use the default gcc version.  gcc  is pretty much up2date on pCP.
2. We add RPI "model specific" compiler options
3. The PcP folks already went not long ago from static to dynamic linking.
4. We skip the resampling and DSD/DOP capabilties (for now)
5. Debugging can be controlled via userspace command line options.


OK. Let's get started.

You should be able to conclude this exercise in about half an hour btw.

Increase Filesystem

Since we download some libraries and the sources plus the compiling environment, we need to increase the pretty tight default 50MB filesystem to 200MB first - we still have a little less than 800MB of RAM to play with afterwards.

Go to the Main Page and select the "Advanced" or "Beta"mode. Then select "resize FS"






Now set the 200MB size and start the process. The system reboots twice. It'll take two to three minutes.






Once that is done we login via ssh. Meanwhile you know how to do it.



1. First we install the required packages:
###############################

tce-load -wi compiletc wget libasound-dev flac-dev libvorbis-dev libmad-dev 
tce-load -wi mpg123-dev faad2-dev


###############################

2. Download and and unzip the squeezelite sources
###############################

cd /tmp
wget https://github.com/ralph-irving/squeezelite/archive/master.zip

unzip master.zip

cd squeezelite-master



###############################

3. Compile the sources 


#####PI3 + 3B+: ###############################

Last update (Nov-15-2018):


export CFLAGS="-O3 -mcpu=cortex-a53 -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mneon-for-64bits -mfloat-abi=hard"

make clean
make


Below is the old set of flags - just as reference:
export CFLAGS="-O3 -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -fno-delayed-branch -fno-selective-scheduling2 -fno-whole-program -mfloat-abi=hard -fno-fast-math"

###############################

For those who run a PI2 you might want to try a PI2 specific compiler flags instead of above:

###############################

export CFLAGS="-O3 -mcpu=cortex-a7 -mfpu=neon-vfpv4  -mfloat-abi=hard -funsafe-math-optimizations"
make clean
make

################################

4. Install the binary

This step applies to pCP >= 3.5 !

###############################


sudo su


cp -f squeezelite /mnt/mmcblk0p2/tce/squeezelite-custom

chmod 777 /mnt/mmcblk0p2/tce/squeezelite-custom

sync
reboot

###############################


As sson as system is up'n running again, you have to enable the new custom binary in the browser under "Squeezelite Settings".





Done.


Hint: 

You now could take your new squeezelite-custom binary from that 200MB image 

and move it to your already backed-up lean 50MB image to the same spot as described above! "/mnt/mmcblk0p2/tce" .This way you'd be able to run the 50MB image with the new binary and without all the extra packages and larger partition.



That'll be it.

As usual. Make a backup if everything is up'n running fine.



Once more. You'll be lacking the resampling, dsd, infrared, gpio features when using above slim binary!   I guess most of you'll get along with it anyhow. 


Enjoy your new speedy binary. Please, let me know if it makes a difference.





2 comments:

  1. Hi Klaus,

    What can I do if I am unable to resize the file system?

    Perhaps because I expanded the SD card a few months ago it tells me "WARNING: Not enough space available for expansion (only 4 MB) (Choose a size between the current partition size: 7707 MB and the maximum partition size: 7711 MB"

    Any thoughts?

    Thanks

    Orlando

    ReplyDelete
    Replies
    1. Just go ahead. You maxed-out your partition already.
      However.
      You havn't been following the series from 1-5.
      Better try that!

      Delete