Skip to content

Instantly share code, notes, and snippets.

@samdoshi
Last active Jan 30, 2022
Embed
What would you like to do?
Running SuperCollider insider Docker with Jack & NetJack2

Assumptions

  • The host OS is Linux
  • You're running jack_dbus, it is correctly configured and working.
  • We're going to run Jack with a period of 4096 and a nperiod of 4 to make things as easy as possible.
  • You've got Docker setup correctly and are able to run docker run hello-world

For reference I'm running Arch Linux.

Summary of Makefile targets

  • build: build the Docker image norns/supercollider.
  • run: run the image, leaves you at an sclang terminal, Ctrl-D to exit sclang and the container.
  • run-bash: runs the image, but doesn't start sclang, instead leaves you at a bash prompt.
  • shell: gives you a bash prompt on an already running instance (e.g. either from make run or make run-bash).
  • jack-restart: restarts jack via DBus, sets period to 4096 and nperiod to 4, then loads the netmanager plugin.
  • jack-connect: attempts to connect the Jack outputs from the container to system:playback_*

Getting started

  1. Clone this Gist, and cd to it.

  2. Copy jackdrc_sample to jackdrc and change XX.XX.XX.XX to your computer's primary IP address.

  3. Open 2 terminals.

  4. In the first terminal, run:

    make build
    make run
    

    This should leave you at an sclang prompt. (Type Ctrl-D if you need to exit sclang, that will also exit the Docker container.)

  5. In the second terminal, either run:

    make jack-restart
    

    Or if restarting your Jack daemon is more complex, do it manually and then run:

    jack_load netmanager
    
  6. Back in the first (sclang) terminal we need to boot scsynth by running:

    s.boot;
    

    Watch the output messages, it can be somewhat tricky figuring out if it hasn't succeeded.

    (You may need to press enter to get the sc3> prompt back.)

  7. In the second terminal run jack_lsb, hopefully you'll see 4 extra entries with names starting with norns:. To connect these to your speakers run:

    make jack-connect
    

    Now if you run jack_lsp -c you should hopefully see the connection.

    Alternatively you could use catia to make the connections in a GUI.

  8. Finally, it's time generate some audio from SuperCollider, in the first (sclang) terminal:

    { SinOsc.ar(440)!2 }.play;
    

    then to stop (all) sound:

    s.freeAll;
    

    Fingers crossed it worked and there were no audio glitches.

Testing audio performance

Try some of the sc140 compositions (be-warned some of them are deliberately glitchy). After pasting one into the sclang command line you'll need to type s.freeAll; to stop audio.

No 11 works well:

play{VarSaw.ar((Hasher.ar(Latch.ar(SinOsc.ar((1..4)!2),Impulse.ar([5/2,5])))*300+300).round(60),0,LFNoise2.ar(2,1/3,1/2))/5}//#supercollider

Other notes

I have had constant XRUNs from Jack causing audio glitches just with a SinOsc playing, but at other times no XRUNs at all. I think that the "network latency" value (set with -l in the jackdrc file) and the period and nperiod values set in the Makefile affect this. Sometimes it works perfectly, sometimes not!

For OS X / Windows users, when running with Docker for Mac / Windows there will be issues getting a network connection from the container to the host (due to the intermediate VM that is used). It's possible that the gateway.docker.internal network address may be part of the solution to that issue.

FROM debian:9
ENV LANG=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV SC_VERSION=3.9.3
RUN apt-get update -q && \
apt-get install -qy apt-utils && \
apt-get dist-upgrade && \
groupadd we -g 1000 && \
useradd we -g 1000 -u 1000 -m -G audio
RUN apt-get install -qy \
build-essential \
bzip2 \
ca-certificates \
cmake \
git \
jackd2 \
libasound2-dev \
libavahi-client-dev \
libcwiid-dev \
libfftw3-dev \
libicu-dev \
libjack-jackd2-dev \
libreadline6-dev \
libsndfile1-dev \
libudev-dev \
libxt-dev \
pkg-config \
unzip \
wget
RUN mkdir -p /tmp/sc && \
cd /tmp/sc && \
wget -q https://github.com/supercollider/supercollider/releases/download/Version-$SC_VERSION/SuperCollider-$SC_VERSION-Source-linux.tar.bz2 -O sc.tar.bz2 && \
tar xvf sc.tar.bz2
RUN cd /tmp/sc/SuperCollider-Source && \
mkdir -p build && \
cd build && \
cmake -DCMAKE_BUILD_TYPE="Release" \
-DBUILD_TESTING=OFF \
-DSUPERNOVA=OFF \
-DNATIVE=OFF \
-DSC_WII=OFF \
-DSC_QT=OFF \
-DSC_ED=OFF \
-DSC_EL=OFF \
-DSC_VIM=OFF \
.. && \
make -j && \
make install
USER we
COPY ["jackdrc", "/home/we/.jackdrc"]
CMD sclang
/usr/bin/jackd -R -d net -a XX.XX.XX.XX -l 5 -n norns
build: Dockerfile jackdrc
docker build -t norns/supercollider .
run: build
docker run --rm -it \
--privileged --ulimit rtprio=95 --ulimit memlock=-1 --shm-size=256m \
--name norns \
norns/supercollider
run-bash: build
docker run --rm -it \
--privileged --ulimit rtprio=95 --ulimit memlock=-1 --shm-size=256m \
--name norns \
norns/supercollider \
bash
shell:
docker exec -it norns bash
jack-restart:
jack_control stop
jack_control start && jack_control dps nperiods 4 && jack_control dps period 4096 && jack_load netmanager
jack-connect:
jack_connect norns:from_slave_1 system:playback_1
jack_connect norns:from_slave_2 system:playback_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment