Skip to content

Commit

Permalink
Brought README_BELA.md up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliomoro committed Jan 11, 2019
1 parent 081c694 commit 8c9206e
Showing 1 changed file with 35 additions and 72 deletions.
107 changes: 35 additions & 72 deletions README_BELA.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This file is Dan's, Marije's and Giulio's notes about compiling SC on [Bela](htt
This branch contains that plus other modifications to get the SC source code master branch building.
The main addition in this branch is a **Xenomai/Bela audio driver for scsynth**, to use Bela's ultra-low-latency audio thread *instead* of jack/portaudio, and **plugins to access the analog and digital channels of the Bela-cape**

> *NOTE:* This guide assumes you have the [Bela image v0.2.0b](https://github.com/BelaPlatform/bela-image/releases/tag/v0.2.0b) or later. Where differences arise between versions below, you will see a note with "vX.X.X"
> *NOTE:* This guide assumes you have the [Bela image v0.3.0](https://github.com/BelaPlatform/bela-image-builder/releases/tag/v0.3.0) or later.
> *NOTE:* You need to get the latest version of the Bela code in order for Supercollider to compile.
Expand All @@ -22,112 +22,74 @@ All of the commands here are to be executed *on the Bela device itself*. Normall
Preparation
===========

Plug in an ethernet cable (or connect to the Internet some other way, see also [Bela Documentation](https://github.com/BelaPlatform/Bela/wiki/Getting-started-with-Bela#software-setup)). Then we need to (a) install/update packages and (b) set the system time:

a) See below at compiling and installing

b) Set the system time (probably not needed if the board gets the date from the DHCP server automatically):
Make sure the system time on the board is up to date. This is ensured by simply opening the Bela IDE in a web browser and loading the page, or from the console, if the board is connected to the internet:

dpkg-reconfigure tzdata
ntpdate pool.ntp.org
date # make sure this gives the right result

Working partition
=================

On my Bela's SD card I added an extra partition and mounted it at `/extrabela` - all my work will be in this partition.
You'll need at least maybe 500 MB spare (estimated).

mkdir /extrabela
mount /dev/mmcblk0p3 /extrabela

Actually I added this line to my /etc/fstab so the partition automounts:

/dev/mmcblk0p3 /extrabela ext4 noatime,errors=remount-ro 0 1
or from the console, if the board is NOT connected to the internet, running from the host something like

ssh -tt -o StrictHostKeyChecking=no -o ConnectTimeout=5 [email protected] "sudo date -s \"`date '+%Y%m%d %T %z'`\""

Get the source code
===================

My modified source code is in this git branch here. If your Bela is still connected to the network you can grab it directly:
My modified source code is in this git branch here. If your Bela is connected to the network you can grab it directly:

cd /extrabela
git clone --recursive -b bela_hackery_v02_master https://github.com/sensestage/supercollider.git
cd ~/
git clone --recursive -b bela https://github.com/BelaPlatform/supercollider.git
cd supercollider


Compiling and installing
========================

You will need to connect your board to the internet in order to install the pre-requisites.

Update apt source list:

apt-get update

Otherwise, `git clone` it on your computer and `scp` it over.

### On Bela image v0.2.x(Debian Wheezy):

We need gcc-4.8 / g++-4.8 as 4.9 causes a weird bug (https://github.com/supercollider/supercollider/issues/1450):

apt-get install -t jessie gcc-4.8 g++-4.8

Get the newest cmake:

apt-get -t jessie install cmake # need this updated version

Get dependent libraries:

apt-get install -t jessie libudev-dev
This version of Supercollider will not compile on this image. Please update your image: https://github.com/BelaPlatform/bela-image-builder/releases

### On Bela image v0.3.x(Debian Stretch):

We need a couple of libraries:

apt-get install libxt-dev libx11-dev libudev-dev

Before we compile, here are two optional steps to make your workflow faster

1. installing `ccache` makes repeated builds faster, if you have spare disk space for it. It's especially helpful if you're going to be changing the cmake build scripts.

```
apt-get install ccache # requires internet access
mkdir /root/.ccache
echo "cache_dir = '/extrabela/ccache'" >> ~/.ccache/ccache.conf
```

2. alternatively, use `distcc` to make all your builds faster by off-loading the actual compilation to your host computer. You need to:
* install a cross-compiler for gcc-4.8 on your host (e.g.: [this](http://bela.io/downloads/gcc-linaro-arm-linux-gnueabihf-2014.04_mac.pkg) for Mac or a `g++-4.8-arm-linux-gnueabihf` package for your Linux distro)
* install `distcc` on your host and make sure your cross-compiler is in the `PATH` (e.g.: on the host `export PATH=$PATH:/usr/local/linaro/arm-linux-gnueabihf/bin/`)
* install a cross-compiler for gcc-6.3 or clang 3.9 on your host (e.g.: [this](http://files.bela.io/gcc/arm-bela-linux-gnueabihf.zip) or download clang 3.9 from the LLVM website for Mac or a `g++-6.3-arm-linux-gnueabihf` package for your Linux distro).
* then follow instructions here to setup a working distcc environment https://forum.bela.io/d/724-distcc-distributed-compilation-with-bela
* on the host, launch `distccd` with something like `distccd --verbose --no-detach --daemon --allow 192.168.7.2 --log-level error --log-file ~/distccd.log` (and then `tail ~/distccd.log` for errors)
* on the board install `distcc` with `apt-get install -t jessie distcc`
* if you get an error during compilation where it cannot find some stdlib includes (e.g.: `#include <chrono>`), it may well be that `cmake` is trying to force `clang` to use `libc++` (with `-stdlib=libc++`). You can override this by editing your distcc-... executable and adding `-stdlib=libstdc++` at the end of the `$@` line.
* then on the board run the following before the `cmake` commands below:

```
export DISTCC_HOSTS="192.168.7.1"
export CC="/usr/bin/distcc arm-linux-gnueabihf-gcc-4.8"
export CXX="/usr/bin/distcc arm-linux-gnueabihf-g++-4.8"
export CC="distcc-clang" # or other as appropriate, see forum post above
export CXX="distcc-clang++" # or other as appropriate, see forum post above
```

NOTE: make sure you don't pass `-march=native` to the compiler when using `distcc`, or it will compile natively. So make sure you do not pass `-DNATIVE=ON` to `cmake`
NOTE: make sure you don't pass `-march=native` to the compiler when using `distcc`, or it will compile natively. Therefore, make sure you do NOT pass `-DNATIVE=ON` to `cmake`, as per below

Then here's how to build:

# note that we explicitly choose the compiler version 4.8 here too, whichever command we use

mkdir /extrabela/build
cd /extrabela/build
mkdir ~/supercollider/build
cd ~/supercollider/build

# here's the command WITHOUT ccache
cmake /extrabela/supercollider -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8 -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DINSTALL_HELP=OFF -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DNATIVE=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DINSTALL_HELP=OFF -DNO_X11=ON -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DNATIVE=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela

# or here's the command WITH ccache
cmake /extrabela/supercollider -DCMAKE_C_COMPILER=/usr/lib/ccache/gcc-4.8 -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++-4.8 -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DINSTALL_HELP=OFF -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DNATIVE=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela
cmake .. -DCMAKE_C_COMPILER=/usr/lib/ccache/clang -DCMAKE_CXX_COMPILER=/usr/lib/ccache/clang-3.9 -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DNO_X11=ON -DINSTALL_HELP=OFF -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DNATIVE=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela

# or here's the command WITH distcc (it will infer the compilers from the `export CC CXX` above
cmake /extrabela/supercollider -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DINSTALL_HELP=OFF -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela
cmake .. -DNOVA_SIMD=ON -DSSE=OFF -DSSE2=OFF -DNO_X11=ON -DINSTALL_HELP=OFF -DSC_QT=OFF -DSC_IDE=OFF -DSC_EL=OFF -DSC_ED=OFF -DSC_VIM=OFF -DSC_HIDAPI=OFF -DSUPERNOVA=OFF -DNO_AVAHI=ON -DENABLE_TESTSUITE=OFF -DAUDIOAPI=bela
make

The `make` step will take a little while, about 30 minutes when using plain `gcc` or `ccache` (you can try `make -j2` or `make -j3` with `distcc`), more like 10 minutes when using `distcc`. It seems it is stuck for a long time at compiling the BinaryOpUGens, but it will get past that.
The `make` step will take a little while, about 30 minutes when using plain `gcc` or `ccache` (you can try `make -j2` or `make -j3` with `distcc`), more like 10 minutes when using `distcc`. It seems it is stuck for a long time at compiling the `BinaryOpUGens.cpp`, but it will get past that.

Next we install:

Expand Down Expand Up @@ -166,7 +128,7 @@ So now you should have scsynth running on the device. You should be able to send
BELA I/O's
==========

I/O support for the BeLa is implemented.
I/O support for the Bela is implemented.

The startup flag ```-J``` defines how many analog input channels will be enabled, the startup flag ```-K``` how many analog output channels will be enabled, the startup flag ```-G``` how many digital channels will be enabled; by default all are set to 0.

Expand Down Expand Up @@ -285,21 +247,22 @@ Here is a breakdown of the options for running *scsynth* and how to set them up

Monitoring its performance
======================================================
Here's a tip from a Bela user on how to check CPU load and "mode switches" for the running program, to make sure it's running properly in realtime etc. (A "mode switch" is something to be avoided: it means the code is dropping out of the Xenomai real-time execution and into normal Linux mode, which can be caused by certain operations in the realtime thread.)
Here's a tip on how to check CPU load and "mode switches" for the running program, to make sure it's running properly in realtime etc. (A "mode switch" is something to be avoided: it means the code is dropping out of the Xenomai real-time execution and into normal Linux mode, which can be caused by certain operations in the realtime thread.)

watch -n 0.5 cat /proc/xenomai/stat
watch -n 0.5 cat /proc/xenomai/sched/stat

which produces output like:

<pre>
Every 0.5s: cat /proc/xenomai/stat Fri Apr 1 12:37:24 2016

CPU PID MSW CSW PF STAT %CPU NAME
0 0 0 159371 0 00500080 76.4 ROOT
0 2282 1 1 0 00b00380 0.0 scsynth
0 2286 1 2 0 00300380 0.0 mAudioSyncSignalTask
0 2288 2 159368 1 00300184 21.0 bela-audio
0 0 0 251165 0 00000000 1.9 IRQ67: [timer]
Every 0.5s: cat /proc/xenomai/sched/stat bela: Fri Jan 11 00:39:12 2019

CPU PID MSW CSW XSC PF STAT %CPU NAME
0 0 0 835043 0 0 00018000 79.0 [ROOT]
0 14390 5 5 14 1 000480c0 0.0 scsynth
0 14404 34655 69562 69517 0 00048042 4.4 mAudioSyncSignalTask
0 14405 1 69782 104649 0 00048046 14.3 bela-audio
0 0 0 744555 0 0 00000000 0.8 [IRQ16: [timer]]
0 0 0 34899 0 0 00000000 1.0 [IRQ181: rtdm_pruss_irq_irq]
</pre>

the "MSW" column indicates mode switches; this number should NEVER increase in the bela-audio thread. It is fine if it increases on a task that runs occasionally, but keep in mind that each mode switch carries an additional overhead.
Expand All @@ -314,7 +277,7 @@ SuperCollider comes with a built-in set of UGen plugins but there's an extra set
cd sc3-plugins
mkdir build
cd build
cmake -DSC_PATH=/extrabela/supercollider -DCMAKE_C_COMPILER=/usr/lib/ccache/gcc-4.8 -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++-4.8 -DCMAKE_C_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -O2" -DCMAKE_CPP_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -O2" ..
cmake -DSC_PATH=~/supercollider -DCMAKE_C_COMPILER=/usr/lib/ccache/gcc-4.8 -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++-4.8 -DCMAKE_C_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -O2" -DCMAKE_CPP_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -O2" ..
make
make install

Expand Down

0 comments on commit 8c9206e

Please sign in to comment.