philippe44 / AirConnect

Use AirPlay to stream to UPnP/Sonos & Chromecast devices
Other
3.44k stars 217 forks source link

Apple Music Lossless & AirPlay #356

Closed CarlBernard closed 3 years ago

CarlBernard commented 3 years ago

Hello,

First, thanks for this lovely little piece of software. Thanks thanks thanks.

Apple Music has started streaming in lossless format in both CD quality (16bit / 44.1k) and high resolution (24bit / 96k, 24bit / 196k). Apple AirPlay 1 and 2 are capable of sending up to 16 bit / 44.1k in lossless ALAC format. I use my Naim UnitiQute 1 amplifier via AirPlay (= AirConnect) and everything works fine but I'm not sure what format I am sending via my iPhone X (AAC lossy or ALAC lossless) to my Mac Mini running AirConnect UPNP.

I read on the Naim Audio forum (https://community.naimaudio.com/t/apple-music-hifi-tier-incoming/16445/632) that at the moment the only way to enjoy lossless is via cable as Apple Music via AirPlay decodes the file from ALAC to AAC before sending it to the receiver. To do a further test, I also tried TIDAL in high resolution via AirPlay but my NAIM receiver informs me that it is always receiving 44.100Hz even when I am sending it 96k or 192k. I have configured AirConnect to send the file to the receiver in WAV format. Should I use PCM or other codec in the ".xml" config file? Does AirConnect always decodes the file only in the 16bit / 44.1k format or send the file as received without any modification?

Is it possible to know which audio format (example: AAC, ALAC, FLAC), bit resolution and sample rate is received by AirConnect before sending it via UPNP to the receiver? In ALSA, I remember, through a command from the terminal it was possible to verify this with

cat / proc / asound / card0 / pcm0p / sub0 / hw_params

but it was not possible to know what the codec was.

jelockwood commented 3 years ago

I don't claim to be an expert in this but…

Normal Apple Music uses AAC at I believe 256Kbps, the new service gives you the choice of Apple Lossless. If you are using AAC it is a lossy format.

AirPlay1 and AirPlay2 use ALAC.

If you had say a CD ripped to ALAC and stored in iTunes (now Music) and streamed it via AirPlay it would be ALAC to ALAC and unchanged. I would have expected that Apple Music streamed in Apple Lossless CD quality and then re-streamed via AirPlay would be the same. If however you are using Apple Music in higher than CD quality it would seem currently it has to be downscaled to CD quality for AirPlay2.

As far as I am aware TOSLink and SPDIF connections both use PCM. No current Mac has these connections any more. A USB audio interface would let you use a hardwired connection.

Another hardware option would be to use Apple Music streaming in above CD quality but again use a USB or Thunderbolt hardware audio interface - this time directly connected to speakers not via a wireless system or TOSLink or SPDIF. This approach in theory would let you benefit from the above CD quality.

I therefore believe at the moment that AirPlay2 is limited to CD quality i.e. 16bit/44.1Khz but I also believe that theoretically it could do 24bit/48KHz via a software update if Apple allowed it.

Arguably you cannot hear the full 16bit/44.1KHz let alone 24bit/48KHz. I would therefore suggest leaving Apple Music configured to 16bit/44.1KHz and then ALAC streaming via AirPlay2 should work fine.

An interesting implication is that if Apple Music streaming service does offer above CD quality then this implies the streaming from Apple to your Apple device is using ALAC in above CD quality - which ALAC supports but equally it might imply a version of the AirPlay2 being used between Apple and your device further suggesting AirPlay2 could be upgrade. What is less clear is how well 3rd party products which currently support AirPlay2 could cope with this either in hardware or firmware.

CarlBernard commented 3 years ago

We all know that AirPlay 1 and 2 right now can't handle formats above 16bit / 44.1k. The problem right now is not whether AirPlay can or cannot handle high definition formats. For this problem we hope there will be good news in the future. The problem today is that Apple Music Lossless via AirPlay is not Lossless even for 16 / 44.1 formats as Apple has decided that via AirPlay the Lossless format becomes lossy (ALAC becomes AAC).

To this I also want to add another thing.

Even if Apple Music had transmitted via AirPlay in ALAC format to the receiver we could not be sure that that file is lossless as the ALAC format is a "container" that can contain any audio file (example: I convert a file with AAC lossy format or mp3 in an ALAC or FLAC format file = the lossy file even if it is present in a lossless container always remains a lossy file).

For this reason I asked if it was possible to check what is the bit rate per second that reaches AirConnect.

I am attaching a screenshot of a NAIM audio technician who demonstrates that the bit rate per second and the format that the device receives via AirPlay is lossy (Audio Format AAC-LC / Bit Rate 237.8 kbps). Schermata 2021-06-11 alle 14 59 11

philippe44 commented 3 years ago

AirConnect receives ALAC or raw PCM from its controller / source, there is no AAC involved. Then I re-encode and send to the player either FLAC, PCM/WAV or MP3. So to be crystal clear AirConnect does NOT receive AAC from controllers. Now, what was that file before it has been sent over AirPlay, I have no idea. The controller can do any sort of transcoding it wants. All I know is that it sends lossless ALAC or raw PCM

philippe44 commented 3 years ago

Even if Apple Music had transmitted via AirPlay in ALAC format to the receiver we could not be sure that that file is lossless as the ALAC format is a "container" that can contain any audio file (example: I convert a file with AAC lossy format or mp3 in an ALAC or FLAC format file = the lossy file even if it is present in a lossless container always remains a lossy file).

ALAC is not a container, it is a codec. You are probably referring to MP4 which indeed is a container that can include ALAC or AAC. Now, AirPlay does not send audio in a container, but it sends "raw" codec frames (to simplify)

As said in my previous response, I only support PCM and ALAC in my AirPlay manifest, hence AirConnect will always receive one of these. AFAIK, there is support for AAC and AAC-ELD in AirPlay 1 but I don't support these.

CarlBernard commented 3 years ago

Hello,

Thanks for the reply.

I asked the same question on the shairport-sync forum

https://github.com/mikebrady/shairport-sync/issues/1205

and I got the same answer you gave me.

It seems that shairport-sync may be somewhat lossless ..

Question: Is AirConnect the same as shairport-sync except for the UPNP side?

philippe44 commented 3 years ago

No, AirConnect is not related by any mean to shairport-sync. I'm aware of shairport-sync of course, but we don't share code.

philippe44 commented 3 years ago

But as a summary, AirConnect receives 16@44.1 alac or plain PCM and it translates it to raw pcm/or wav (just adding header) or flac lossless (0..9 compression level) or mp3 lossy (64..320 Kbps) and then send that to the Chromecast device.. Nothing more nothing less. Does that answer your question? I'm not sure anymore what you're looking for

CarlBernard commented 3 years ago

Hello Philippe,

Thanks for the reply and thanks again for this nice software.

philippe44 commented 3 years ago

YW