Using Norns as an AirPlay receiver

Edit:
Moved from question to development. Full set of install instructions posted below. Many thanks to @okyeron for suggesting to use Jack and for testing.


Original post:

Hi,
The output of my Norns clone is connected to an audio system. Since this device has bluetooth, wifi, a DAC and some jacks, I’m wondering if I could also send audio from my Mac to this device, using airplay, and while still being able to use Norns and all the scripts in parallel.

Actually, there’s an Airplay for Raspberry Pi solution called SharePort Sync and this what I’m looking at. The stable release supports Airplay 1 and the dev supports airplay 2. The readme states:

Do you think it’s possible to have it running concurrently with the Norns system ? Or should I expect some conflicts between dependencies, software etc ?

It’s just an idea, I’m wondering if anybody tried a similar setup already…

Thanks :wink:


Edit: Quick test

Following the instructions provided on Github, I’ve installed Shairport-sync on the Norns shield.
“Norns” shows up in the list of Airplay devices available (image above).

Unfortunately, Shairport-sync cannot use my DAC WM8731 because it’s “already in use” (used by the Norns software).

Just for the sake of trying, I then plugged a cheap Behringer USB soundcard to Norns and edited the configuration file of Shairport telling it to use the USB sound card instead of the DAC.

Yes, it works but it’s not optimal yet. I can now play audio from my Mac through Norns, or more precisely through the Raspberry Pi running Norns but… I guess it might be possible to edit the huge .conf file of Shairport and maybe to configure Norns so they both use the same soundcard, but I’m not an expert of Alsa so…

6 Likes

jack_connect is your friend.

Assuming Shairport-sync can route to jack that is already running. I’ll test here for fun. :slight_smile:

1 Like

Ah thanks @okyeron, I’ll have a look at it tomorrow. Please let me know if you succeed in the meantime :slight_smile:

I don’t know if it can but I haven’t read the whole documentation. I know it can be built --with-pipe (include an optional backend module to enable raw audio to be output through a unix pipe) and can also output to Jack theoritically. Now, can a simple RPI 3B handle all that without losing packets etc while still running Norns in parallel ? Not sure of that yet… - I haven’t tried to launch a Norns script, I got a “Supercollider fail” after updating my Norns clone - Well, the audio quality is not that great so far, a bit glitchy, but sure it’s fun to see “Norns” in the list of Airplay devices :slight_smile:

Looks like you need to build from source to have the --with-jack option. I tried the debian package and it does not seem to have jack enabled.

I’m trying this config right now:
./configure --sysconfdir=/etc --with-alsa --with-jack --with-avahi --with-ssl=openssl --with-metadata --with-soxr --with-systemd


EDIT

Got it working after removing the debian package, compiling myself with the flags above.

needed some extra packages (I think a couple of these are already installed tho):
apt install autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev libsoxr-dev

Had to copy the shairport-sync.conf sample file over the one that the deb package installed. Then added this in the jack section along with setting output_backend = "jack":

        client_name = "shairport-sync"; // Set this to the name of the client that should appear in "Connections" when Shairport Sync $
        autoconnect_pattern = "system:playback_[12]"; // Set this to a POSIX regular expression pattern that describes the ports you w$

Problem tho - the system service does not work - prob due to permissions and/or startup order. (Jack needs to already be running before shairport-sync can connect to it)

so I disabled the system service and then ran it from the command line.

shairport-sync -vu

will give you verbose output.

2 Likes

Great ! That’s awesome, congrats :clap:
You tried on Fates / Rpi 4 ? No glitchy audio output with both Norns and Shairport running simultaneously ?

About systemd, I remember there’s a way to set a service to run after: another one. Could be a solution, if it’s reliable. I will try that, first thing tomorrow morning and report back.

Thanks!

Didn’t do an extensive test. Just got audio coming out with nothing loaded on norns. Yes on fates/pi4.

2 Likes

It’s working. I can play audio via Airplay from my computer on the Raspberry Pi and run Norns “Awake” at the same time, Norns Shield line out connected to my HIFI system, without glitch. Next, I’ll work on the Systemd part to have Shairport start automatically.


Installing Shairport Sync - Airplay for RPI - on Norns

Prerequisites:

sudo apt install autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev libsoxr-dev avahi-daemon libavahi-client-dev sox jackd2

Installing Alac (Apple codec):

git clone https://github.com/mikebrady/alac.git
cd alac
autoreconf -fi
./configure
make
sudo make install

Installing Shairport:

cd && git clone https://github.com/mikebrady/shairport-sync.git
cd shairport-sync
autoreconf -fi
./configure --sysconfdir=/etc --with-alsa --with-jack --with-avahi --with-ssl=openssl --with-metadata --with-soxr --with-systemd --with-apple-alac
make
sudo make install

Optional - installing SPS-Alsa-explore:

git clone https://github.com/mikebrady/sps-alsa-explore.git
cd sps-alsa-explore
autoreconf -fi
./configure
make

(testing : ./sps-alsa-explore should list your DAC)

Configuration:

sudo nano /etc/shairport-sync.conf
(Or use VsCode on your computer to edit this large file)

  • Uncomment line 19 and set it to output_backend = “jack”
  • Uncomment lines 146
  • Uncomment line 147 and set it to autoconnect-pattern = “system:playback_[12]“
  • Uncomment line 154 and set it to soxr_resample_quality = "medium" (or high)

Loads of additional adjustments are possible in this file !

Testing:

Launch Shairport manually using shairport-sync -vu and set the Airplay output to Norns on your computer.

Starting Airplay/Shairport-sync automatically on startup:

sudo systemctl enable shairport-sync
sudo nano /lib/systemd/system/shairport-sync.service

and modify the file so it reads:

[Unit]
Description=Shairport Sync - AirPlay Audio Receiver

Requires=mn_jackd.service
After=mn_jackd.service
Requires=avahi-daemon.service
After=avahi-daemon.service
Wants=network-online.target
After=network.target network-online.target

[Service]

ExecStart=/usr/local/bin/shairport-sync
User=we

[Install]
WantedBy=multi-user.target

Jackd and Shairport need to be run by the same user we and Shairport needs to start after jackd.


Improvements & tweaks:
Tested on a RPI3B and 3B+ I think the quality is fine. No big dropouts or glitch

  • It would be nice to adjust the line level in the .conf file to match the specs of the WM8731 DAC. At first, I thought there was no sound, but it was actually very low on the Mac side.
  • There’s probably a way to improve the latency; This can probably be tweaked in the .conf file of Shairport too, or in the configuration file of Jack. I’m no Linux expert…
  • This resampling thing - done with Sox- Does Norns run at 48khz or can we avoid resampling 44k to 48k to save a bit of CPU ? Not sure about that.
  • and this jack “realtime” warning…

Sidenotes:

I had to set line 154 of the .conf to soxr_resample_quality = "medium" or high /// Setting it to “none“ would cause the following error *fatal error: The JACK server is running at the wrong sample rate (48000) for Shairport Sync. Must be 44100 Hz.

If it’s proven reliable, the following improvement would be awesome imo: Airplay as an audio source for sampling in Norns… - Perhaps as a mod ? - I guess it’s all a question of routing audio on the RPI, working with Jack etc. If somebody wants to add this possibility, that would be nice. There’s also a possibility to display the metadata on the screen, but that’s entering the Norns software territory…

12 Likes

Reviving this just now but you should just be able to do jack_connect shairport-sync:out_L SuperCollider:in_1 just not sure if supercollider is the right input versus another of the options. Jack_lsp gives crone, soft cut, and supercollider (along with shairport-sync).

2 Likes

you probably want crone:input_1 and _2.

2 Likes

Yep! that ended up working. The snippet ends up being
jack_connect shairport-sync:out_L crone:input_1
jack_connect shairport-sync:out_R crone:input_2

1 Like

Thanks a lot for sharing this solution @zebra & @inkering
I will try as soon as possible :wink:

1 Like

Totally! I was also thinking it’d be fun to set up a norns script to show metadata (if playing from iTunes), and a potentially a volume adjuster, eq setup for better speaker use.

Shairport exposes metadata for some programs in /tmp/shairport-sync-metadata

EDIT:
I ended up making a little utility for this in script form: https://github.com/Inkering/sherry.

For now it just lets you switch between having shairport patched to the input channel on norns and having it just patched to the output (for speaker listening).

2 Likes

I had to install libssl1.0-dev as well

In the shairport-sync.service I had to rename the jack service which is called differently on my Shield.

norns-jack.service instead of mn_jack.service

Mar 26 07:30:42 norns shairport-sync[603]: Cannot lock down 107350048 byte memory area (Cannot allocate memory)
Mar 26 07:30:42 norns shairport-sync[603]: fatal error: The JACK server is running at the wrong sample rate (48000) for Shairport Sync. Must be 44100 Hz.
Mar 26 07:30:42 norns systemd[1]: shairport-sync.service: Main process exited, code=exited, status=1/FAILURE
Mar 26 07:30:42 norns systemd[1]: shairport-sync.service: Failed with result 'exit-code'.

Thank god I once already worked through this on my main RPi … not that I feel proficient but at least I know I fixed it with setting up a .asoundrc for sample rate conversion

cat  ~/.asoundrc
pcm.!default
{
  type plug
  slave sl1
}

ctl.!default
{
  type hw
  card 0
}

pcm_slave.sl1
{
  pcm "hw:0,0"
  format S16_LE
  channels 2
  rate 48000
}

pcm_slave.norns
{
    pcm "hw:0,0"
    rate 48000
}

Didn‘t you have to do this? Sadly it still saying it can‘t connect due to sample rate issues (basically nothing changed…).

I‘m done with my wisdom at this point. Actually it took 3 years for me to get jack and shairport working in my other setup :upside_down_face: I’m not the most gifted nerd, I suppose

2 Likes

Did you happen to edit the shairport config file to the right sample rate?

See above:

1 Like

Yes, that’s right. My own install is based on Fates, not Norns Shield. Filenames might have different names.

I can’t remember exactly how I did but @inkering is right: You need to set a resample quality in the configuration file of Sox, otherwise it won’t work. Unfortunately, this eats resources too and leads to higher latency and occasional glitches on a simple 3b RPI like mine, but it can’t be set to “none”