I have compared again Spotify AirPlay streamed from AppleTV via AirPlay to my Hakai against Spotify Connect streamed from the same AppleTV to the same Hakai.
In short, the AirPlay streamed version sounds terrible. I think mobile bluetooth into my car hifi sounds more enjoyable!
I wondered what could be contributing and if it could be improved - given that Källa can make AirPlay musical (
https://www.lejonklou.com/forum/viewtop ... =13&t=5560) - so I took a look at the shairport-sync documentation.
It is worth summarising the rather complex chains involved in these two play-back scenarios:
Via AirPlay
Spotify App on Apple TV > AirPlay (over network) encoded as ALAC > shairport-sync on Hakai > ALSA audio driver > USB DAC > amp > speakers
Via Spotify Connect
Spotify App on Apple TV > Spotify Connect protocol (over network) encoded as AAC (I think) > vollibrespot on Hakai > ALSA audio driver > USB DAC > amp > speakers
At what point do the two paths become the same and we can probably ignore differences? On the face of it they have common components from the ALSA service on Hakai onwards, and are different up to that point.
ALSA supports either PCM or bitstream. The USB DAC just supports PCM, so it is reasonable to think that both routes send PCM to ALSA and the path is the same for both from that point onwards.
Shairport-sync and vollibrespot are two different Linux processes (registered as services) and independently send PCM to ALSA.
The other music service I use on Hakai is MPD. This service is not involved in either of the two scenarios I'm comparing. It also happens to sound better, but that's another story.
Returning to the original question, I am surprised at just how different
AirPlay + Shairport-sync sounds compared to
Spotify Connect + vollibrespot, and in particular how
bad the AirPlay route sounds.
So how do these two services work? Well, as far as I can tell they work very differently.
AirPlay + Shairport-sync
According to the shairport-sync documentation, AirPlay running on the AppleTV takes control of timing of playback. It sends the encoded and streamed audio from the AppleTV to the shairport-sync process on the Hakai and in that data it includes timing instructions. If shairport-sync cannot output fast enough it will drop audio frames, and if it does not get audio in time from the AppleTV it will generate fake frames.
On the face of it, this sounds like a bad idea. Any variation in processing or communication between the AppleTV and shairport-sync could result in audio being either dropped or fabricated.
To minimise the risk of shairport-sync running out of music data, it buffers for a configurable period (currently 2 seconds). This buffering doesn't protect shairport-sync from dropping frames if it can't keep up with the AppleTV.
I'm not sure if I can persuade shairport-sync to report any frames dropped or injected to see if that is the cause of the poor sound quality.
If I can, I am tempted to fork the shairport-sync code and remove the timing behaviour to see if it sounds better.
Spotify Connect + vollibrespot
In contrast, Spotify Connect does not stream any audio to vollibrespot. Instead it tells vollibrespot to pull the audio from Spotify's servers. The AppleTV is not in the audio data path once vollibrespot starts playing music. Vollibrespot does not rely on the Spotify servers for timing the audio playback.