mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.29k stars 574 forks source link

Sample format not available for external DAC #501

Closed raspbeguy closed 7 years ago

raspbeguy commented 7 years ago

Hello, I am unable to use shairport-sync with my external DAC (works on default sound card). I use output device hw:CARD=C1,DEV=0 (this is set the same way on MPD, which works correctly). I also tried hw:1 and hw:1,0 without success. Whenever I send sound from a iOS device, I've got this output (verbosity set to 1):

mars 25 23:38:40 mpdpi shairport-sync[845]: Value read for output rate is 44100.
mars 25 23:38:40 mpdpi shairport-sync[845]: Output device name is "hw:CARD=C1,DEV=0".
mars 25 23:38:40 mpdpi shairport-sync[845]: Version: "3.0.2-OpenSSL-Avahi-ALSA-soxr-metadata-sysconfdir:/etc"
mars 25 23:38:40 mpdpi shairport-sync[845]: statistics_requester status is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: daemon status is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: rtsp listening port is 5000.
mars 25 23:38:40 mpdpi shairport-sync[845]: udp base port is 6001.
mars 25 23:38:40 mpdpi shairport-sync[845]: udp port range is 100.
mars 25 23:38:40 mpdpi shairport-sync[845]: Shairport Sync player name is "MPDpi".
mars 25 23:38:40 mpdpi shairport-sync[845]: Audio Output name is "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: on-start action is "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: on-stop action is "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: wait-cmd status is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: mdns backend "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: stuffing option is "0" (0-basic, 1-soxr).
mars 25 23:38:40 mpdpi shairport-sync[845]: resync time is 0.050000 seconds.
mars 25 23:38:40 mpdpi shairport-sync[845]: allow a session to be interrupted: 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: busy timeout time is 120.
mars 25 23:38:40 mpdpi shairport-sync[845]: drift tolerance is 0.001995 seconds.
mars 25 23:38:40 mpdpi shairport-sync[845]: password is "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: ignore_volume_control is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: volume_max_db is not set
mars 25 23:38:40 mpdpi shairport-sync[845]: playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
mars 25 23:38:40 mpdpi shairport-sync[845]: disable_synchronization is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: use_mmap_if_available is 1.
mars 25 23:38:40 mpdpi shairport-sync[845]: output_rate is 44100.
mars 25 23:38:40 mpdpi shairport-sync[845]: output_format is 3 (0-unknown, 1-S8, 2-U8, 3-S16, 4-S24, 5-S24_3LE, 6-S24_3BE, 7-S32).
mars 25 23:38:40 mpdpi shairport-sync[845]: audio backend desired buffer length is 0.150000 seconds.
mars 25 23:38:40 mpdpi shairport-sync[845]: audio backend latency offset is 0.000000 seconds.
mars 25 23:38:40 mpdpi shairport-sync[845]: volume range in dB (zero means use the range specified by the mixer): 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: zeroconf regtype is "_raop._tcp".
mars 25 23:38:40 mpdpi shairport-sync[845]: decoders_supported field is 1.
mars 25 23:38:40 mpdpi shairport-sync[845]: use_apple_decoder is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: no special mdns service interface was requested.
mars 25 23:38:40 mpdpi shairport-sync[845]: configuration file name "/etc/shairport-sync.conf" resolves to "/etc/shairport-sync.conf".
mars 25 23:38:40 mpdpi shairport-sync[845]: metdata enabled is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: metadata pipename is "(null)".
mars 25 23:38:40 mpdpi shairport-sync[845]: metadata socket address is "(null)" port 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: metadata socket packet size is "500".
mars 25 23:38:40 mpdpi shairport-sync[845]: get-coverart is 0.
mars 25 23:38:40 mpdpi shairport-sync[845]: Successful Startup
mars 25 23:38:40 mpdpi shairport-sync[845]: avahi: avahi_register.
mars 25 23:38:40 mpdpi shairport-sync[845]: avahi: register_service.
mars 25 23:38:40 mpdpi shairport-sync[845]: avahi: request to add "_raop._tcp" service without metadata
mars 25 23:38:41 mpdpi shairport-sync[845]: avahi: service 'B661DDA17533@MPDpi' successfully added.
mars 25 23:38:49 mpdpi shairport-sync[845]: New RTSP connection from [2a01:e34:ec12:8880:e4:7275:f8cc:91e]:49640 to self at [2a01:e34:ec12:8880:6bc2:9806:32f:8aae]:5000.
mars 25 23:38:49 mpdpi shairport-sync[845]: Play connection from user agent "AirPlay/301.44.3".
mars 25 23:38:49 mpdpi shairport-sync[845]: Active-Remote string seen: "485126310".
mars 25 23:38:50 mpdpi shairport-sync[845]: DACP-ID string seen: "B21CB48110250B2".
mars 25 23:38:50 mpdpi shairport-sync[845]: Set up play connection from 2a01:e34:ec12:8880:e4:7275:f8cc:91e to self at 2a01:e34:ec12:8880:6bc2:9806:32f:8aae.
mars 25 23:38:50 mpdpi shairport-sync[845]: Output sample ratio is 1.
mars 25 23:38:50 mpdpi shairport-sync[845]: Output frame bytes is 4.
mars 25 23:38:50 mpdpi shairport-sync[845]: Output bit depth is 16.
mars 25 23:38:50 mpdpi shairport-sync[845]: Hammerton Decoder used on encrypted audio.
mars 25 23:38:50 mpdpi shairport-sync[845]: Output sample ratio is 1
mars 25 23:38:50 mpdpi shairport-sync[845]: Output written using MMAP
mars 25 23:38:50 mpdpi shairport-sync[845]: audio_alsa: Sample format 2 not available for device "hw:CARD=C1,DEV=0": Invalid argument
mars 25 23:38:50 mpdpi shairport-sync[845]: avahi: avahi_unregister.
mars 25 23:38:50 mpdpi shairport-sync[845]: Request to shut down all rtsp conversation threads
mars 25 23:38:50 mpdpi shairport-sync[845]: RTSP shutdown requested.
mars 25 23:38:50 mpdpi shairport-sync[845]: Closing down RTSP conversation thread...

For info my DAC is a Cambridge DacMagic 100.

mikebrady commented 7 years ago

Thanks for the post. Looking at the manual for your device, on page 18 it looks like it does not accept 16/44100. Try setting Shairport Sync to 24 bit output in the configuration file.

raspbeguy commented 7 years ago

It does accepts 16/44100, it works perfectly with MPD. Anyway, I changed the setting from S16 to S24 as you asked and it doesn't work better. Now I have this error (6 instead of 2):

mars 26 08:42:03 mpdpi shairport-sync[2756]: audio_alsa: Sample format 6 not available for device "hw:1,0": Invalid argument
mikebrady commented 7 years ago

Thanks for the update. The thing is, MPD may be resampling the material to suit the output device, so just because MPD accepts 16/44100 material, it does not mean that that's what it sends to the device. A way to check whether the device accepts 16/44100 is to try using aplay with a 16/44100 sample.

In the manual, in USB 1.0 mode (which I think is the default for Linux), it says 24 bit. There are a number of 24 bit formats – have you tried them all?

raspbeguy commented 7 years ago

Thanks for your answer. No, MPD isn't resampling anything, I disabled it, so MPD sends unaltered data to the DAC. This might be slightly out of topic, but here is my mpd config:

audio_output {
    type            "alsa"
    name            "My ALSA Device"
    device          "hw:CARD=C1,DEV=0"
    mixer_type      "none"
    auto_channels   "no"
    auto_format "no"
    auto_resample   "no"
}

Besides I can also check this by running the following command:

cat /proc/asound/card1/pcm0p/sub0/hw_params

I can garantee you that the DAC accepts 16/44100.

mikebrady commented 7 years ago

Very mysterious! Can you share the output of $ cat /proc/asound/card1/pcm0p/sub0/hw_params please? Just FYI, another user had a similar problem, though with a different card, in issue #463. Also, when you look at it with alsamixer, what device number does it give you?

raspbeguy commented 7 years ago

I'm very sorry, it seems that once more I spoke without being sure at 100%. Actually you seem to be right. MPD is sending S24_3LE audio to the DAC, I don't know why. I set it up in shairport-sync and it is now working. I'm concerned by those results though. It leads me to 3 problems:

  1. The sound is constantly altered (16bit -> 24bit) which leads to audiophile concerns.
  2. My Raspberry Pi USB ports are working in version 1.1 and not in 2.0. Why ?
  3. Why is 16bit mode not working in USB 1.1 and 24bit mode does???

Anyway, that's not a problem related to shairport-sync (but if have a response I would appreciate it).

mikebrady commented 7 years ago

Thanks for the reply, and it's good to get to the the source of the issue.

To address your problems:

  1. By itself, that should not be an issue with Shairport Sync: if you are using a hardware mixer for volume control, then Shairport Sync merely multiplies each sample by 256 and passes it through otherwise unaltered. So, translating from 16 to 24 bit with Shairport Sync should be quasi bit perfect. However, before you break out the champagne, the interpolation used to by Shairport Sync to maintain synchronisation – adding or removing samples occasionally ("basic"), or occasionally resampling 352-sample sequences to get 351 or 353 samples ("soxr") – means that, in general, it won't be bit perfect.
  2. The "Version 1.0" and "Version 2.0" stuff refers to some USB Audio Class 1 and USB Audio Class 2 standards, not the standard of the USB link itself. TBH, I have never figured out the status of USB Audio support on Linux.
  3. It seems to be a design decision with Cambridge Audio – maybe they can answer that question.
raspbeguy commented 7 years ago
  1. Isn't the interpolation method only about sample rate? Here the sample depth is the problem, I don't know it this apply here.
  2. So this isn't proper to the Raspberry Pi, but to the entire Linux system? That's interresting.
  3. Dunno...
mikebrady commented 7 years ago

What I mean is the process used by Shairport Sync to keep the audio in sync – basically it inserts or deletes audio frames to keep the output in step when the source and destination sample rates, while nominally the same, are slightly off.

raspbeguy commented 7 years ago

I see. Well, anyway thank you for the help, I guess the ticket can be closed now that the problem has been explained (even if it means more inverstifation for me).

mikebrady commented 7 years ago

Okay, I'll close this, thanks. If you find anything definitive on the subject of USB Audio 2.0 support in Linux, I'd be glad to hear of it.