ALSA output. Need help with period_time and buffer_time

Need help with MPD?
Post Reply
KatePrince
Posts: 2
Joined: July 12th, 2019, 9:34 am

ALSA output. Need help with period_time and buffer_time

Post by KatePrince » July 12th, 2019, 12:26 pm

Hi, boys, I'm trying to make a smart BoomBox with Onion Omega2+ based on mt7688. Here is Linux OpenWRT 19.07, alsa-utils-1.1.7, alsa-lib-1.1.8 (is it ok with different versions of alsa-lib and utils?), ffmpeg-3.4.6, upmpdcli-1.4.0, libmpdclient-2.16, libsndfile-2019-04-21 and I'm just compiled MPD-0.21.11, my configs:
___________________________________________________________________________
. output/release
-Dprefix=${workspace_loc:/MPD-0-21-11/install}
--cross-file /home/kate/meson-0.50.0/cross/ubuntu-mips.txt
-D libsamplerate=enabled
-D alsa=enabled
-D buildtype=release
-D debug=false
-D dbus=disabled
-D adplug=disabled
-D ao=disabled
-D audiofile=disabled
-Dbzip2=disabled
-D cdio_paranoia=disabled
-D curl=enabled
-D expat=enabled
-D ffmpeg=enabled
-D fluidsynth=disabled
-D gme=disabled
-D icu=disabled
-D id3tad=enabled
-D iso9660=disabled
-D jack=disabled
-D lame=disabled
-D libmpdclient=enabled
-D mad=disabled
-D mikmod=disabled
-D mms=enabled
-D modplug=disabled
-D mpcdec=disabled
-D mpg123=disabled
-D nfs=disabled
-D openal=disabled
-D opus=disabled
-D pulse=disabled
-D shine=disabled
-D shout=enabled
-D sidplay=disabled
-D smbclient=disabled
-D sndfile=enabled
-D sndio=disabled
-D solaris_output=disabled
-D soxr=disabled
-D sqlite=disabled
-D systemd=disabled
-D twolame=disabled
-D upnp=enabled
-D vorbis=disabled
-D vorbisenc=disabled
-D wavpack=disabled
-D webdav=enabled
-D wildmidi=disabled
-D zeroconf=disabled
-D zlib=enabled
-D zzip=disabled
___________________________________________________________________________
I'm running MPD with -12 nice priority and running upmpdcli, it works, but on my hardware i2s driver I have a lot of underruns, especially on high quality audio 192/24. I think problem in hw params (buffer and period).
___________________________________________________________________________
My mpd.conf:
music_directory "~/music"
playlist_directory "/var/.mpd/playlists"
db_file "/var/.mpd/database"
log_file "/var/.mpd/log"
pid_file "/var/.mpd/pid"
state_file "/var/.mpd/state"
user "root"
bind_to_address "localhost"
port "6600"
log_level "verbose"
input {
plugin "curl"
# proxy "proxy.isp.com:8080"
# proxy_user "user"
# proxy_password "password"
}
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:0,0" # optional
mixer_type "null" # optional
## mixer_device "default" # optional
## mixer_control "PCM" # optional
## mixer_index "0" # optional
}
___________________________________________________________________________
My hardware i2s driver's params:
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER,
.formats = SNDRV_PCM_FMTBIT_S16_LE |
SNDRV_PCM_FMTBIT_S24_LE,
.channels_min = 2,
.channels_max = 2,
.period_bytes_min = PAGE_SIZE, \\ 512
.period_bytes_max = PAGE_SIZE * 2, \\ actually not max, it can be PAGE_SIZE * 8
.periods_min = 2, \\ actually idk what this param means ¯\_(ツ)_/¯
.periods_max = 128, \\ should I enlarge it?
.buffer_bytes_max = 128 * PAGE_SIZE * 2,
.fifo_size = RALINK_I2S_FIFO_SIZE, \\ 32
___________________________________________________________________________
I have underruns when just aplay 192/24 audio, but it's much much more when playing through mpd
___________________________________________________________________________
root@OpenWrt:~# aplay /root/1kHz\(24x192\)cut.wav -v
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
Plug PCM: Linear conversion PCM (S24_LE)
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S24_3LE
subformat : STD
channels : 2
rate : 192000
exact rate : 192000 (192000/1)
msbits : 24
buffer_size : 96256
period_size : 1024
period_time : 5333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 96256
stop_threshold : 96256
silence_threshold: 0
silence_size : 0
boundary : 1577058304
Slave: Hardware PCM card 0 'ad1938' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S24_LE
subformat : STD
channels : 2
rate : 192000
exact rate : 192000 (192000/1)
msbits : 32
buffer_size : 96256
period_size : 1024
period_time : 5333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 96256
stop_threshold : 96256
silence_threshold: 0
silence_size : 0
boundary : 1577058304
appl_ptr : 0
hw_ptr : 0
root@OpenWrt:~# cat /sys/kernel/debug/10000a00.i2s/stats
tx stats
below threshold 2276594
under run 116
over run 0
dma fault 0
___________________________________________________________________________

My mpd log file return no mistakes but hw_params seems wrong:
...
Jul 11 14:30 : decoder_thread: probing plugin sndfile
Jul 11 14:30 : decoder: audio_format=192000:32:2, seekable=true
Jul 11 14:30 : alsa_output: opened hw:0,0 type=HW
Jul 11 14:30 : alsa_output: buffer: size=1024..131072 time=5333..682667
Jul 11 14:30 : alsa_output: period: size=512..1024 time=2666..5334
Jul 11 14:30 : alsa_output: default period_time = buffer_time/4 = 500000/4 = 125000
Jul 11 14:30 : alsa_output: format=S24_LE (Signed 24 bit Little Endian)
Jul 11 14:30 : alsa_output: buffer_size=96000 period_size=1000
Jul 11 14:30 : output: opened "My ALSA Device" (alsa) audio_format=192000:24:2
Jul 11 14:30 : output: converting in=192000:32:2 -> f=192000:32:2 -> out=192000:24:2
...
root@OpenWrt:~# cat /sys/kernel/debug/10000a00.i2s/stats
tx stats
below threshold 6573140
under run 130587
over run 0
dma fault 0
___________________________________________________________________________
I'm not a stupid girl, but I really need help. Mb I need to change something in my hardware i2s driver, or just set right period_time/buffer_time and buffer_size/buffer_before_play?

max
Forum team
Posts: 938
Joined: January 15th, 2013, 3:43 pm

Re: ALSA output. Need help with period_time and buffer_time

Post by max » July 12th, 2019, 1:21 pm

Your MPD log doesn't show any underruns. This means alsa-lib and your kernel driver disagree on whether underruns happened. This is something I can't help with, because MPD is not involved. MPD has met all its deadlines, and the underruns apparently happen later in the chain. If MPD had missed any deadline, you would have seen it in the log.

KatePrince
Posts: 2
Joined: July 12th, 2019, 9:34 am

Re: ALSA output. Need help with period_time and buffer_time

Post by KatePrince » July 13th, 2019, 10:00 am

max wrote:
July 12th, 2019, 1:21 pm
Your MPD log doesn't show any underruns. This means alsa-lib and your kernel driver disagree on whether underruns happened. This is something I can't help with, because MPD is not involved. MPD has met all its deadlines, and the underruns apparently happen later in the chain. If MPD had missed any deadline, you would have seen it in the log.
Yeah, but it's in integration with alsa, when I aplay 192/24 it uses one hw parameters, but MPD uses another one. Mb someone knows how I need to open my pcm playback, hw params have to use. Mpd have buffer_time and period_time config in alsa output I experimented some, used same params like aplay do, it do a lot of underruns at begin, but after some time it's clear.

max
Forum team
Posts: 938
Joined: January 15th, 2013, 3:43 pm

Re: ALSA output. Need help with period_time and buffer_time

Post by max » July 13th, 2019, 10:08 pm

As long as your driver fails to properly report those xruns to userspace, there's little we can do about the situation. Maybe you can reduce the number of xruns by using some "magic" numbers for those buffer settings, but it doesn't change the fact that your driver (or some other entity behind MPD) is buggy/broken. I can't help with broken drivers.

Post Reply