<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body smarttemplateinserted="true" bgcolor="#FFFFFF" text="#000000">
    <div id="smartTemplate4-template">
      <p>I don't have a solution, but please post yours if you find one.
        I've been trying to get a working sound out of my Windows 7 VM
        for a while now, every sound card available in libvirt produces
        just noise and crackling.</p>
      <p>Maybe it would be great to have a virtio sound card. Things are
        apparently not going so well with emulating real hardware.<br>
      </p>
    </div>
    <br>
    <div class="moz-signature"><i>--Regards, Aleksei</i>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">
      <hr><br>
      <b>From:</b> Manuel Ullmann<br>
      <b>Sent:</b> Tuesday, December 20, 2016 5:41AM<br>
      <b>To:</b> Libvirt-users<br>
      <b>Subject:</b> [libvirt-users] Audio in Windows 10 VM is
      distorted. Using ALSA.</div>
    <blockquote cite="mid:87bmw71fwc.fsf@sonnengebleicht.fritz.box"
      type="cite">
      <pre wrap="">Hi,

I can’t seem to find a solution for my last VM issue.
I have distorted sound, when I play the Windows 10 device test
sound. Only the Windows sound is affected. Mpd of the host is playing just fine
meanwhile. I am using ich9 as emulated card, which is detected and
installed correctly. The VM is using vfio-igd passthrough, so  vnc or
spice are not used.
I tried to match the Windows driver configuration, which only supports
16 bit output. I have a 24 bit USB headphone amplifier, which does not
support it (S32_LE only). Trying direct playback on the PCH card jack
did not help though.

The headphone amplifier is connected via optical Toslink, so there is
standard snd_hda_intel output used (snd_usb_audio is not involved).
Passing the USB part through I get much clearer output, but still have
popping sounds. Googling around, they seem to be quite common on Windows
10, although I had it working fine on two bare-metal machines.

I have tried fixed settings matching the ones of the dmixed device
too. Don’t know, what is polled with enabled poll option. I also tried
sdl and pulseaudio, which did not help. For the latter not so surprising
since it is an Alsa pipe. The former was worse.

The goal of this setup is having the same playlist state on both
systems and using the better audio framework for music playback (Windows uses
too much software layers). Of course the popping sounds on audio device
passthrough also would be annoying, but that might be a different issue.

Best regards,
Manuel

used alsa device:
pcm.dmixed {
        type asym
        playback.pcm {
                # See plugin:dmix at <a class="moz-txt-link-freetext" href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html">http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html</a>
                type dmix

                # Don't block other users, e.g. the Timidity midi-player daemon
                # <a class="moz-txt-link-freetext" href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html">http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html</a>
                ipc_key_add_uid false

                ipc_key 1025
                ipc_perm 0660
                ipc_gid audio

                # Don't put the rate here! Otherwise it resets the rate & channels set below, as shown by:  cat /proc/asound/card0/pcm0p/sub0/hw_params
                slave {
                        # 2 for stereo, 6 for surround51, 8 for surround71
                        channels 2
                        pcm {
                                format S16_LE
                                #format S32_LE

                                #rate 44100
                                rate 48000

                                # <a class="moz-txt-link-freetext" href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html">http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html</a>
                                # Maybe helps
                                nonblock true
                                type hw
                                card "PCH"
                                device 0
                                subdevice 0
                        }

                        # mplayer2 chooses 1024
                        # period_size 512 with buffer_size 16384 stops crackling in xmame
                        # 320 breaks flash - <a class="moz-txt-link-freetext" href="https://bbs.archlinux.org/viewtopic.php?id=129458">https://bbs.archlinux.org/viewtopic.php?id=129458</a>
                        #period_size 512
                        period_size 1024

                        # 4096 might make sound crackle
                        # mplayer2 chooses 8192. Half-Life 2 chooses 16384.
                        # If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=2048
                        buffer_size 8192
                }
        }
        capture.pcm "schneeball"
}

libvirt xml snippets:

    <sound model='ich9'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </sound>
    ...
    <qemu:env name='QEMU_AUDIO_DRV' value='alsa'/>
    <qemu:env name='QEMU_DAC_FIXED_SETTINGS' value='0'/>
    <qemu:env name='QEMU_DAC_TRY_POLL' value='0'/>
    <qemu:env name='QEMU_DAC_TIMER_PERIOD' value='0'/>
    <qemu:env name='QEMU_DAC_BUFFER_SIZE' value='0'/>
    <qemu:env name='QEMU_DAC_PERIOD_SIZE' value='0'/>
    <qemu:env name='QEMU_DAC_DEV' value='dmixed'/>

_______________________________________________
libvirt-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:libvirt-users@redhat.com">libvirt-users@redhat.com</a>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/libvirt-users">https://www.redhat.com/mailman/listinfo/libvirt-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>