Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

qt - What are the defaults for ALSA's .asoundrc?

I'm working with Qt 5.13.2 on a Yocto-based embedded Linux box and specifically QSoundEffect. Qt has been configured to use ALSA rather than PulseAudio. ALSA's aplay is able to play a WAV file smoothly. QSoundEffect playback is notably choppy. I've been trying to adjust ALSA's configuration in .asoundrc to smooth things out. For example:

pcm.!default {
    type hw
    card 0
    rate 44100
}

ctl.!default {
    type hw
    card 0
    periods 100
    period_size 4410
    buffer_size 35280
}

This does solve the choppy/stuttering playback but it also has the undesirable side effect of blocking simultaneous QSoundEffect plays. If I don't use a .asoundrc file, I can get simultaneous playback. But of course, the stuttering is there.

So, the question is: what are the default values for various settings (not well-documented, btw)? Or better yet, what setting should I be looking at? BTW, if I use the defaults by not having a .asoundrc file, I see "(snd_pcm_recover) underrun occurred" messages when I play a QSoundEffect.

question from:https://stackoverflow.com/questions/65910779/what-are-the-defaults-for-alsas-asoundrc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured out the initial part of things. First, having any .asoundrc file present regardless of the existence of the buffer or period settings overrides any settings that exist in /etc/asound.conf. That at least makes sense as far as the documentation is concerned.

It took some digging but apparently what I need is called mixing and there is no mixing happening by default. Fortunately, the ALSA documentation has a working example.

From alsa-project.org

pcm.!default {
        type plug
        slave.pcm "dmixer"
}

pcm.dmixer  {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:1,0"
                period_time 0
                period_size 1024
                buffer_size 4096
                rate 44100
        }
        bindings {
                0 0
                1 1
        }
}

ctl.dmixer {
        type hw
        card 0
}

I put this into a .asoundrc file and changed hw:1,0 to hw:0,0 because my default sound card is 0. Voila! I'm now able to play multiple QSoundEffects simultaneously.

I'm still getting buffer underrun notices so there's likely some work left to do to figure out the settings for period size and buffer size.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...