Saturday, 14 July 2018

RPi and iTunes <-> IOS app for music

After finally setting up Kodi to use a DAC mounted on Raspberry Pi for controlling/serving my music controlled by an IOS device, I re-discovered that IOS devices, via the Apple iTunes remote, can control remote iTunes.

But how's that help?

On Linux there has been long supported a iTunes server (a daap implementation) called mt-daapd that was I previously used with a Roku Soundbridge M1000 back in the early/mid 2000s: the Roku had a LED display and a nice little physical remote control but that seems a little antiquated/painful searching a large library.

The unmaintained mt-daapd codebase was forked and available on the Raspberry Pi as forked-daapd which means that we have a working iTunes server and a IOS app. Furthermore, the forked-daapd supports non-IOS clients/remotes so this can be an all round/cross platform solution.

Pairing IOS devices

Once the forked-daapd is running, we need to pair the IOS device with the iTunes server which can be done via the web front end for the new versions or by the following summaried as:
  • tail the log file, looking for remote: Discovered remote '...'
  • open the IOS Remote app and select "manually select library", a 4digit code is displayed on your IOS device
  • under your music library folder, create a file with a .remote extension which contains 2 lines:
    • line#1 - your device name as per log file
    • line#2 - the code that is displayed on your IOS device
    When the file is saved, forked-daapd will pair with your device and your IOS will show your iTunes server
With this in place, you are now able to control your music with another option to Kodi.

Note, that whilst the stock version (22.0) from the Raspberry Pi/debian repo is functional, the version available from the maintainer's repo includes builds for RPi and additional features such as smart playlists

Configuring output for DAC

The one gotcha for my setup that has Kodi installed (and running) alongside forked-daap is that by default, the output is sent to Kodi and then output through the configuration in Kodi (to my DAC). This wasn't apparent until looked at the web frontend.


Allo Boss DAC, using a TI/Burr Brown PCM1522 chip common in other RPi DACs with good measurements

Selecting the 'local' alsa playback device needed some tweaking.
audio {
nickname = "Computer"
type = "alsa"
# card = "default"
card = "hw"
mixer = "Analogue"
}
I only have the DAC enabled for alsa and so this is the default device but the tricky part was to get the correct mixer name but this is available by running amixer
$ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=IQaudIODAC
IQaudIODAC,
Default Audio Device
...
hw:CARD=IQaudIODAC,DEV=0
IQaudIODAC,
Direct hardware device without any conversions
...

$ amixer
Simple mixer control 'DSP Program',0
Capabilities: enum
Items: 'FIR interpolation with de-emphasis' 'Low latency IIR with de-emphasis' 'High attenuation with de-emphasis' 'Fixed process flow' 'Ringing-less low latency FIR'
Item0: 'Ringing-less low latency FIR'
Simple mixer control 'Analogue',0
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 1
Mono:
Front Left: Playback 1 [100%] [0.00dB]
Front Right: Playback 1 [100%] [0.00dB]
Simple mixer control 'Analogue Playback Boost',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 1
Front Left: 0 [0%] [0.00dB]
Front Right: 0 [0%] [0.00dB]
...
The DAC seemed to have multiple mixer controls but the simple trick in identifying the right one was to also run alsamixer to see which one affected volume output.


With the same setup as in Kodi, where we have disabled the on-board sound, playing music will select the DAC as the output. Done.

Finally a Raspberry Pi audio/music server solution

Rediscovering the DAAP server has probably concluded a rather long search for the right music server for me. One of the first projects for my raspberry Pi was to allow a simple way to access my digital music, starting with an unsuccessful venture with Volumio. Whilst Volumio provided an easy-out-of-the-box solution that is probably suitable for many people, it failed for me in a number of ways:
  • it was difficult to install other applications and use for other projects: basically, it was a bespoke/non-general linux distribution
  • the control interface was mainly through a web interface with its mpd based backend was buggy/slow/deficient - trying to browse access a large number of files would cause IOS browser to refresh and unresponsive. The web interface was nice looking however. Other mpd clients are available but they all feel unpolished, unsuitable for tablets for easy control/unsupported (mpod) or too basic (ympd)
Kodi as the solution was close and again is probably very good for most people. However, the one area Kodi suffered for me is it is rather a heavy application. I have my digital music on a USB harddisk mounted on a wired RPi where the music is then NFS exported to other machines (desktop and other Raspberry Pis) of differing processing ability. One machine on the network is a 1st generation, single core, RPi 1 Model B which would suffer running Kodi but would happily run forked-daapd taking ~10% of the CPU when pulling files off the network and playing the media through the headphone jack feeding an amplifier.

forked-daapd is simply an application that can be installed to any flavor of RPi and it takes care of the media indexing to an sqlite3 DB backend whilst providing an interface to an IOS native appl (Remote) that is unlikely to be unsupported given iTunes is the center of Apple's home music server. As a bonus, forked-daapd also provides as a simple and very usable web interface (with clear separation of concerns from frontend/backend) for controlling playback.

forked-daapd (v26.2) web interface
Good to come full circle to a solution that evolved from the code that solved the same problem over a decade earlier.

No comments:

Post a Comment