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. If you're still not happy with the result!?!? Hmmh.

OK. We could do a little more. ;)

However.

Perhaps you should wait  for another week trying this Measure. I strongly recommend to get used to the performance of your recently manipulated PcP setup first. 


The result of this exercise might not be that earth shattering as you'd expect it to be.

What can we still do !?!?

There are two big areas that still can be addressed. 



1. The squeezelite binary
2. The kernel




The kernel is very difficult to handle under piCorePlayer. I provided different optimized  kernels incl. a realtime kernel to the Moode project. 
Doing that for piCorePlayer is much more difficult. First I'm not in charge. 2nd TinyCore Linux is a pretty complex system. No wonder that PcP provides a 2nd image for the 
advanced audio kernel version.

I am in contact to the pCP person in charge from time to time though. 
Perhaps I can manage to arrange something related to the rt-kernel in the future.

However. Let's get one more manageable thing done. The squeezelite binary.
You can do it in half an hour to an hour.

What we can do is making the binary running more efficient. 
More efficient !?!? Yep. I hear you.

Beside coding of quality sources there are 

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

which usually have impact on a binary performance.

I e.g. measured 10-20% difference just by changing compiler options on the widely used 
linpack benchmarking tool.

We'll gonna apply 2. and 4. during this exercise. 

* The PcP folks already went not long ago from static to dynamic linking.
* And we'll use the same gcc version as the PcP folks. This one is pretty much up2date.
* Debugging can be controlled via userspace command line options.


Let's get started.


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.





You can even do this after running the earlier exercises! 

Once finished you need to ssh login. Meanwhile you know how to do it.


NOTE:  The resulting binary will work on the PI3 only!



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 


###############################
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 -pipe -fstack-protector --param=ssp-buffer-size=4 -DVISEXPORT -DLINKALL"
make clean
make


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

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

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

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 only!

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



sudo su


cp -f squeezelite /mnt/mmcblk0p2/tce/squeezelite-tune-slim


cd /mnt/mmcblk0p2/tce
rm  squeezelite 2>/dev/null
chmod 777 squeezelite-tune-slim
ln -s squeezelite-tune-slim squeezelite-custom


sync

reboot


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


Now you have to enable the new custom binary in the browser under "Squeezelite Settings".





For older < 3.5 pCP try this:

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

sudo su

cp -f squeezelite /mnt/mmcblk0p2/tce/squeezelite-tune-slim

cd /mnt/mmcblk0p2/tce
rm  squeezelite 2>/dev/null
chmod 777 squeezelite-tune-slim
ln -s squeezelite-tune-slim squeezelite
sync

reboot


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



Done.


Hint: 

You now could take your new squeezelite 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.



I almost forgot. 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.





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