[Stk] Improving RtApiAlsa

Tristan Matthews le.businessman at gmail.com
Thu Feb 17 12:36:22 PST 2011


Hello Stk-users/devs,

I've been working on fixing STK's alsa backend so that RtApiAlsa doesn't hog
the sound device it's using (i.e. other programs can use it at the same
time). I've been doing the work on github, in an appropriately-named
"fix_alsa" branch:

https://github.com/tmatth/stk/tree/fix_alsa

There are two things that had to be changed:
1) snd_pcm_open needed to be called with the SND_PCM_NONBLOCK flag, not the
SND_PCM_ASYNC flag. The SND_PCM_ASYNC flag just causes SIGIO to be emitted
every period (which wasn't getting handled anywhere). Furthermore, when
writing to the device in NONBLOCK mode, you have to wait on the device
before writing to it (with snd_pcm_wait).
2) The interface to use by default should be "default", not "hw:0". This is
because using the hw:0 interface name means ALSA will try to open it for
exclusive use. The device pointed to by "default" can be changed in one's
.asoundrc file.

The second point is a bit trickier, because RtAudio by default expects to be
able to enumerate the devices by number. ALSA is expecting devices to be
specified by name rather than number, that's why defaulting the first device
is not great behaviour. In my branch, currently I set the device name to
"default" unless the user has specified the HOG_DEVICE flag in their stream
parameters, in which case it will grab the interface corresponding to the
integer deviceID. I discussed this a bit off-list with Stephen Sinclair, but
wanted more feedback since it seems like a poor solution.

Best,
Tristan


-- 
Tristan Matthews
email: tristan at sat.qc.ca
web: http://tristanswork.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20110217/1dc2ecfd/attachment.html 


More information about the Stk mailing list