Duddy Cool Duddy Cool - 1 month ago 20
C++ Question

select audio output divece when using QSoundEffect

I am using

QSoundEffect
to play loops of some short
.wav
files. This class was the solution for me because it allow us to play low latency sounds.

Everything was fine but now I need to select the output device but I haven’t found the way to do this with
QSoundEffect
. I know that using
QAudioDeviceInfo
I can get a list of the available devices and use one of them in the constructor of a
QAudioOutput
object to play a wav file but
QAudioOutput
doesn't allow us to make low latency loops.

So the thing is that I need the functionality of selecting the audio output device that
QAudioOutput
and
QAudioDeviceInfo
but the ability of playing play low latency loops that
QSoundEffect
offers.

In other words I have all the pieces of my desired solution but I don’t know how to put them together.

Answer

Since Qt5.7 the alsa qt plugin (libqtaudio_alsa.so) is using the device "default", this you can configure in /etc/asound.cfg or ~/.asoundrc In the example below I'm selecting dmix plugin as default device:

pcm.dmixed {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    slave.pcm "hw:0,0"
}
pcm.dsnooped {
    type dsnoop
    ipc_key 1025
    slave.pcm "hw:0,0"
}

pcm.duplex {
    type asym
    playback.pcm "dmixed"
    capture.pcm "dsnooped"
}

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

ctl.!default {
  type hw
  card 0
}
Comments