mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.16k stars 569 forks source link

USB DAC too slow, output distorted when using soxr #1245

Closed fesc2000 closed 2 years ago

fesc2000 commented 3 years ago

Hi,

i have been struggling recently with the symptom that after some time of playback the audio output is completely distorted. So before digging further into the issue, maybe someone here has an idea..

(I'm fine if you disregard this issue as off-topic)

My setup is a SoC with a dual-core Atom (CE2752@2GHz) running an embedded linux (buildroot), using alsa to connect a USB DAC (iFi Zen DAC, so not the cheapest one).

From what can be seen from the logs, the output is a little bit too slow (44066Hz), so there is a fair amount of overrun. Without sox resampling, i hear faint crackling when i play a pure sine. Enabling sox, it runs for a while (in the range of seconds to minutes/hours) before all of a sudden the audio is more or less crap (and loud!). CPU load is low, the measured time for resampling (5) is well below the "sox threshold".

Below are the stats, where output ran fine for ~two minutes when this happens before the last line (input comes from an iphone 11). Settings are default:

drift_tolerance_in_seconds = 0.002;
resync_threshold_in_seconds = 0.050;

So my questions are:

Now i wonder what could be the reason for this:

Since i don't remember this happening until recently, i wonder if an oscillator/pll has degraded. I have a piece of spare hardware, but before i exchange oscillators i would like explore a potential software solution.

Note that on mpd (which also runs on this setup) i get occasional drop-outs (ca 1sec), which likely have the same reason. From what i read the way shairport-sync does the adjustment is not how it's done in mpd (it uses sox/libsamplerate before sending towards the DAC, not caring about the true output rate).

Thanks for any idea or pointers where to find more information!

         8.005288668 "player.c:2778"       2.45,    -824.2,     824.2,       27081,      0,      0,      0,      0,   8610,  235,  247,   44100.00,   44132.31,   44066.19,     67.70,    13,   -834.97
         8.004728778 "player.c:2778"       2.48,    -849.7,     849.7,       28084,      0,      0,      0,      0,   8608,  235,  246,   44100.00,   44130.05,   44066.57,     67.70,    13,   -826.39
         8.004527657 "player.c:2778"       2.42,    -829.9,     829.9,       29087,      0,      0,      0,      0,   8598,  235,  246,   44100.00,   44129.47,   44066.45,     67.64,    14,   -828.94
         8.004496160 "player.c:2778"       2.44,    -824.2,     824.2,       30090,      0,      0,      0,      0,   8607,  235,  246,   44100.00,   44129.16,   44065.99,     67.64,    14,   -839.58
         8.003759447 "player.c:2778"       2.40,    -846.9,     846.9,       31093,      0,      0,      0,      0,   8606,  235,  246,   44100.00,   44127.78,   44066.52,     67.64,    14,   -827.39
         8.006519065 "player.c:2778"       2.43,    -844.1,     844.1,       32096,      0,      0,      0,      0,   8622,  235,  246,   44100.00,   44127.14,   44066.30,     67.83,    15,   -832.60
         8.004993543 "player.c:2778"       2.38,    -815.7,     815.7,       33099,      0,      0,      0,      0,   8594,  235,  246,   44100.00,   44126.81,   44065.80,     67.83,    15,   -844.12
         8.004409380 "player.c:2778"       2.51,    -858.2,     858.2,       34102,      0,      0,      0,      0,   8612,  235,  246,   44100.00,   44125.01,   44065.86,     68.62,    17,   -843.33
         8.009109284 "player.c:2778"       2.44,    -815.7,     815.7,       35105,      0,      0,      0,      0,   8616,  235,  247,   44100.00,   44124.75,   44066.36,     68.62,    17,   -832.21
         8.003306510 "player.c:2778"       2.42,    -846.9,     846.9,       36108,      0,      0,      0,      0,   8597,  235,  246,   44100.00,   44122.70,   44066.37,     68.62,    17,   -831.76
         8.006069290 "player.c:2778"       2.49,    -815.7,     815.7,       37111,      0,      0,      0,      0,   8623,  235,  246,   44100.00,   44123.59,   44066.35,     68.62,    17,   -832.37
         8.004265617 "player.c:2778"       2.46,    -849.7,     849.7,       38114,      0,      0,      0,      0,   8606,  235,  246,   44100.00,   44123.30,   44066.25,     68.62,    17,   -834.63
         8.004424178 "player.c:2778"       2.48,    -846.9,     846.9,       39117,      0,      0,      0,      0,   8601,  235,  246,   44100.00,   44123.23,   44066.25,     69.15,    18,   -835.23
         8.006699987 "player.c:2778"       2.46,    -855.4,     855.4,       40120,      0,      0,      0,      0,   8601,  235,  246,   44100.00,   44122.03,   44066.33,     68.91,    19,   -832.95
         8.003519992 "player.c:2778"       2.47,    -790.2,     790.2,       41123,      0,      0,      0,      0,   8604,  235,  246,   44100.00,   44121.71,   44066.46,     68.91,    19,   -830.03
         8.010426087 "player.c:2778"       2.49,    -875.2,     875.2,       42126,      0,      0,      0,      0,   8612,  235,  246,   44100.00,   44120.92,   44066.24,     69.29,    20,   -835.44
         8.004108630 "player.c:2778"       2.44,    -832.7,     832.7,       43129,      0,      0,      0,      0,   8600,  235,  246,   44100.00,   44120.72,   44066.33,     69.29,    20,   -833.54
         8.004505046 "player.c:2778"       2.36,    -827.1,     827.1,       44132,      0,      0,      0,      0,   8606,  235,  246,   44100.00,   44120.53,   44066.20,     69.28,    22,   -836.47
         8.004622450 "player.c:2778"       2.46,    -841.2,     841.2,       45135,      0,      0,      0,      0,   8615,  235,  247,   44100.00,   44120.46,   44066.46,     69.28,    22,   -830.55
         8.003804355 "player.c:2778"       2.39,    -852.6,     852.6,       46138,      0,      0,      0,      0,   8570,  235,  247,   44100.00,   44119.55,   44066.27,     69.28,    22,   -834.68
         8.004575853 "player.c:2778"       2.44,    -807.2,     807.2,       47141,      0,      0,      0,      0,   8549,  235,  247,   44100.00,   44119.74,   44066.26,     69.28,    22,   -834.92
         8.005920465 "player.c:2778"       2.50,    -863.9,     863.9,       48144,      0,      0,      0,      0,   8603,  235,  246,   44100.00,   44118.54,   44066.21,     69.28,    22,   -836.20
         8.005422083 "player.c:2778"       2.39,    -801.6,     801.6,       49147,      0,      0,      0,      0,   8610,  235,  246,   44100.00,   44118.58,   44066.27,     69.28,    22,   -834.80
         8.003729949 "player.c:2778"       2.47,    -846.9,     846.9,       50150,      0,      0,      0,      0,   8583,  235,  247,   44100.00,   44118.41,   44066.17,     69.18,    23,   -836.96
         8.004535894 "player.c:2778"       2.44,    -835.6,     835.6,       51153,      0,      0,      0,      0,   8603,  235,  246,   44100.00,   44118.26,   44065.94,     69.26,    24,   -842.27
         8.009422408 "player.c:2778"       2.50,    -835.6,     835.6,       52156,      0,      0,      0,      0,   8613,  235,  246,   44100.00,   44117.70,   44066.29,     69.26,    24,   -834.36
         8.005439193 "player.c:2778"       2.47,    -832.7,     832.7,       53159,      0,      0,      0,      0,   8607,  235,  247,   44100.00,   44117.77,   44066.31,     69.26,    24,   -833.75
         8.002376801 "player.c:2778"       2.52,    -832.7,     832.7,       54162,      0,      0,      0,      0,   8585,  235,  246,   44100.00,   44116.84,   44066.26,     69.26,    24,   -835.07
mikebrady commented 3 years ago

Thanks for the interesting post. Those are huge levels of correction, and 44066 fps is a bit crazy. Some older DACs ran at 44096.5 fps or something similar, but 44066 is nearly ten times worse, and is a bit mad.

Can I ask you to post the alsa settings please, and also the list of alsa hardware devices that is given at the end of $ shairport-sync -h?

fesc2000 commented 3 years ago

Thanks for the replay. The information that the correction is way too high would mean that i should try to fix my hardware .. Here is some data, not sure what is useful. As said, there are two DACs which behave identical.

# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Audio [iFi (by AMR) HD USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

# amixer
Simple mixer control 'iFi (by AMR) Internal Clock Validity',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]

# shairport-sync -V
3.3.8-mbedTLS-tinysvcmdns-ALSA-jack-stdout-pipe-soxr-convolution-metadata-mqtt-sysconfdir:/etc

# shairport-sync -h
...
Available mDNS backends:
    tinysvcmdns

Available audio backends:
    alsa (default)
    jack
    pipe
    stdout

Settings and options for the audio backend "alsa":
..
    hardware output devices:
      "hw:Audio"

This is also intersting (i didn't look into the details what those values mean). Delay/avail are de/increasing all the time.

# cat /proc/asound/card0/pcm0p/sub0/status

state: RUNNING
owner_pid   : 13061
trigger_time: 1149823.178103486
tstamp      : 1149851.951733678
delay       : -1381120
avail       : 1397516
avail_max   : 1397516
-----
hw_ptr      : 1381132
appl_ptr    : 0

alsa.conf is unmodified version of buildroot installation: alsa.zip

mikebrady commented 3 years ago

Thanks. Could you also include the alsa settings from the Shairport Sync configuration file please, or else the command line options you may be using? (Sorry for being a little unclear.)

mikebrady commented 3 years ago

It may not be your hardware -- let's wait to see your settings.

fesc2000 commented 3 years ago

My shairport-sync.conf is in the zip file

fesc2000 commented 3 years ago

.. And a full log where the corruption happens after some seconds: log.zip

mikebrady commented 3 years ago

Thanks.

Okay, I notice that your output device is set to "default". It may be that the default device is not actually your DAC, but rather an alsa pseudo device. It would be better to set the output to the real hardware output device (as suggested), which might be "hw:Audio" or "hw:0".

The mixer volume control name also looks wrong -- use alsamixer to see what name, if any, to use for the mixer. Set it to full volume using alsamixer and comment out the mixer_control_name in the Shairport Sync settings file -- that is one less variable.

Please do not set the log verbosity to 3 -- it is much too noisy for normal use. Set it to 1 or maybe 2.

fesc2000 commented 3 years ago

This definitely makes a difference, with device="hw:0" it looks like this:

        6.525212963 "player.c:2778"       0.93,    -223.8,     223.8,       64192,      0,      0,      0,      0,   8502,  235,  248,   44100.00,   44115.17,   44102.16,      0.00,     8,     48.98

However, now whenever a correction is applied, audio is corrupted for a short amount of time (or, audible crackling when playing a sine wave):

         8.003210043 "player.c:2778"      -0.28,    -147.3,     147.3,       71213,      0,      0,      0,      0,   8500,  235,  247,   44100.00,   44114.06,   44102.05,      0.00,     7,     46.49

Maybe it's libsoxr which has an issue, at least on this platform. It's strange, but if i now increase the drift tolerance i think i could live with it (as there are no corrections happening any more).

I set verbosity to 3 only briefly to provide the logs.

mikebrady commented 3 years ago

It's good that you've made some headway. It might be worth setting the interpolation to "basic" just to see what happens.

github-actions[bot] commented 3 years ago

This issue has been inactive for 60 days so will be closed 7 days from now. To prevent this, please remove the "stale" label or post a comment.