Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Intermittent loud ticks and no-audio using Spotify
#5
(01-17-2020, 01:10 AM)Tim Curtis Wrote: Try posting your issue in the librespot repo.
https://github.com/librespot-org/librespot

So I did in the "meantime" (almost sorry for taking the time)...  Wink

Also referring to the (at the time of writing this) unresolved topic what could be, but not necessarily, dealing with the same cause:
http://moodeaudio.org/forum/showthread.p...sound.conf

OK, so with release 6.7.1 2020-07-22 still glitches between tracks and when stopping tracks, especially with Spotify Connect.
I was hoping for a bit of improvement, updating from release 6.4.0, but this is not the case.
I even experience more problems with this release over 6.4.0 regarding an inconsistent audio volume levels when switching between radio stations and spotify with sometimes result in extreme loud volumes (probably maxed out) were suddenly the ALSA mixer goes bananas and make your rig sweat.

Regarding librespot I wrote with Jason Gray and he made me have a look at the output of /proc/asound/card*/pcm*p/sub*/hw_params so that is in my case  /proc/asound/card0/pcm0p/sub0/hw_params when Spotify was playing. That resulted in:

access: RW_INTERLEAVED

format: S16_LE
subformat: STD
channels: 2
rate: 44100 (352800/8)
period_size: 225
buffer_size: 22050

According to Jason the period_size is way (!)  too small, because that translates into 196 CPU interrupts per second. For a 0.5 sec buffer a much more reasonable buffer setting would be a buffer size of 22052 and a period size of 5513. That would translate to about 8 CPU interrupts per second.

He said this about it:

Quote:I would advice Moode Audio to rebuild librespot against the current git master. If that doesn't help they can create a new pcm device in asound.conf specifically for librespot and manually set their own buffer params.

He also mentioned that, because with a beafy Pi 4 there is much more power at hand than a Pi zero, it is wise to have even a larger buffer like 1 sec and a 0.25 sec period time for the zero. He could replicate the problem on a zero easily he said.

My guess is, but because I cannot compare it is just a guess, that it could vary from soundcard to soundcard.
In my case I have only the HiFiBerry DAC+ Pro XLR to test.
And by the way, HiFiBerryOS does NOT produce these glitches, despite the same period_size and buffer_size output of hw_params.


It would be great to be able to do some temporary testing and create /etc/asound.conf with some values that would enlarger the period_size and buffer_size, would it be to much to ask to give me something to work with? I would be nice to have something to just fill in the necessary values. I am afraid my C-skills are not up to notch any more since I programmed with it for the last time in the early 90's.

Another thing that Jason mentioned was about consistency, and the importance about having harmony between buffer settings and sample rate + bit depth.
A suggestion for /etc/asound.conf to make all settings match was this piece of code:

Code:
###############################################################################

pcm.hqstereo20 {
   @args [
       SAMPLE_RATE FORMAT SAMPLE_RATE_CONVERTER
       BUFFER_PERIODS BUFFER_PERIOD_TIME
   ]
   # Sampling rate in Hz:
   # 44100, 48000, 88200, 96000...
   # Defaults to 44.1 kHz (CD Quality).
   @args.SAMPLE_RATE {
       type integer
       default 44100
   }
   # Format:
   # S16_LE, S24_LE, S24_3LE, S32_LE...
   # Defaults to S16_LE (CD Quality).
   @args.FORMAT {
       type string
       default S16_LE
   }
   # Resampling algorithm.
   # Defaults to samplerate_linear.
   @args.SAMPLE_RATE_CONVERTER {
       type string
       default samplerate_linear
   }
   # Periods per buffer.
   @args.BUFFER_PERIODS {
       type integer
       default 4
   }
   # Period size in time.
   # Defaults to 125ms (0.125 sec).
   # BUFFER_PERIODS * BUFFER_PERIOD_TIME = buffer time/size
   @args.BUFFER_PERIOD_TIME {
       type integer
       default 125000
   }
   type plug
   rate_converter $SAMPLE_RATE_CONVERTER
   slave {
       channels 2
       rate $SAMPLE_RATE
       format $FORMAT
       pcm {
           type dmix
           ipc_key 1024
           ipc_perm 0660
           ipc_gid audio
           slowptr true
           hw_ptr_alignment roundup
           slave {
               pcm {
                   type hw
                   card {
                       @func refer
                       name defaults.pcm.card
                   }
                   device {
                       @func refer
                       name defaults.pcm.device
                   }
                   subdevice {
                       @func refer
                       name defaults.pcm.subdevice
                   }
                   channels 2
                   rate $SAMPLE_RATE
                   format $FORMAT
               }
               channels 2
               period_size 0
               buffer_size 0
               buffer_time 0
               period_time $BUFFER_PERIOD_TIME
               periods $BUFFER_PERIODS
               rate $SAMPLE_RATE
               format $FORMAT
           }
           bindings {
               0 0
               1 1
           }
       }
   }
}

###############################################################################

# Change to the card number or name that you want to be the default control card.
# Default: 0
defaults.ctl.card 0

# Change to the card number or name that you want to be the default playback card.
# It should usually be the same as defaults.ctl.card.
# Default: 0
defaults.pcm.card 0

# Change to the device number that you want to be the default device on the default card.
# 0 or 1 is usually the correct device number.
# Default: 0
defaults.pcm.device 0

# Change to the subdevice number that you want to be the default subdevice on the default device.
# Should rarely need to be changed.
# Default: -1
defaults.pcm.subdevice -1

pcm.spotify {
   type plug
   # Optional args:
   # SAMPLE_RATE: default: 44100
   # FORMAT: default: S16_LE

   # SAMPLE_RATE_CONVERTER: default: samplerate_linear
   # SAMPLE_RATE_CONVERTER MAP:
   # low: samplerate_linear
   # medium: speexrate
   # High: speexrate_medium
   # Highest/Very High: speexrate_best

   # BUFFER_PERIODS: default: 4
   # BUFFER_PERIOD_TIME: default: 125000

   # Example:
   # 32 bit 96 kHz 1 sec buffer "high quality" sample rate conversion.
   "hqstereo20:SAMPLE_RATE=96000,FORMAT=S32_LE,SAMPLE_RATE_CONVERTER=speexrate_medium,BUFFER_PERIOD_TIME=250000"

   slave.pcm "hqstereo20"
}

###############################################################################

He also added:

Quote:With the above all that has to be overwritten is the slave.pcm definition in pcm.spotify when any of the main audio settings are changed and then they would just have to tell librespot to use the custom "spotify" pcm with ```--device spotify".

Hope this helps to improve Moode and have it glitch / spike / pop - free.
And of course look forward to be of any help regarding testing with a temporary asound.conf file.
Reply


Messages In This Thread
RE: Intermittent loud ticks and no-audio using Spotify - by basmeyer - 10-09-2020, 01:44 PM

Forum Jump: