<div dir="ltr"><div><div><div>Hi,<br><br></div>I found the main reason for sound distortions on my system is guest timer configuration.<br><br></div>The working one is:<br><br><clock offset="localtime"><br>    <timer name="hypervclock" present="yes"/><br>    <timer name="hpet" present="no"/><br>    <timer name="rtc" present="yes" track="guest" tickpolicy="delay"/><br></clock><br>...<br><qemu:commandline>a<br>    <qemu:arg value='-machine'/><br>    <qemu:arg value='kernel_irqchip=on'/><br>    <qemu:arg value='-cpu'/><br>    <qemu:arg value='host,migratable=no,+invtsc,hv_time,+kvm_pv_eoi,hv_relaxed,hv_spinlocks=0x1fff,hv_vendor_id=nv_fuck_you!,kvm=off'/><br></qemu:commandline><br><br></div>The important part here is "host,migratable=no,+invtsc". It gives guest the invariant TSC (CPU must support it). This is a bit of a hack. Everything, except migratable=no, can be configured through proper XML elements, however +invtsc requires migratable=no, and I don't know a way to pass it other than using qemu:arg. Note it completely overrides qemus -cpu parameter created from other tags. Don't paste my qemu:arg of it. Run your VM without it, check libvirt log, and copy from it what is passed to qemu as -cpu parameter, then add migratable=no,+invtsc.<div class="gmail_extra"><br><div class="gmail_quote">2016-12-20 4:41 GMT+02:00 Manuel Ullmann <span dir="ltr"><<a href="mailto:ullman.alias@posteo.de" target="_blank">ullman.alias@posteo.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I can’t seem to find a solution for my last VM issue.<br>
I have distorted sound, when I play the Windows 10 device test<br>
sound. Only the Windows sound is affected. Mpd of the host is playing just fine<br>
meanwhile. I am using ich9 as emulated card, which is detected and<br>
installed correctly. The VM is using vfio-igd passthrough, so  vnc or<br>
spice are not used.<br>
I tried to match the Windows driver configuration, which only supports<br>
16 bit output. I have a 24 bit USB headphone amplifier, which does not<br>
support it (S32_LE only). Trying direct playback on the PCH card jack<br>
did not help though.<br>
<br>
The headphone amplifier is connected via optical Toslink, so there is<br>
standard snd_hda_intel output used (snd_usb_audio is not involved).<br>
Passing the USB part through I get much clearer output, but still have<br>
popping sounds. Googling around, they seem to be quite common on Windows<br>
10, although I had it working fine on two bare-metal machines.<br>
<br>
I have tried fixed settings matching the ones of the dmixed device<br>
too. Don’t know, what is polled with enabled poll option. I also tried<br>
sdl and pulseaudio, which did not help. For the latter not so surprising<br>
since it is an Alsa pipe. The former was worse.<br>
<br>
The goal of this setup is having the same playlist state on both<br>
systems and using the better audio framework for music playback (Windows uses<br>
too much software layers). Of course the popping sounds on audio device<br>
passthrough also would be annoying, but that might be a different issue.<br>
<br>
Best regards,<br>
Manuel<br>
<br>
used alsa device:<br>
pcm.dmixed {<br>
        type asym<br>
        playback.pcm {<br>
                # See plugin:dmix at <a href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html" rel="noreferrer" target="_blank">http://www.alsa-project.org/<wbr>alsa-doc/alsa-lib/pcm_plugins.<wbr>html</a><br>
                type dmix<br>
<br>
                # Don't block other users, e.g. the Timidity midi-player daemon<br>
                # <a href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html" rel="noreferrer" target="_blank">http://www.alsa-project.org/<wbr>alsa-doc/alsa-lib/pcm_plugins.<wbr>html</a><br>
                ipc_key_add_uid false<br>
<br>
                ipc_key 1025<br>
                ipc_perm 0660<br>
                ipc_gid audio<br>
<br>
                # Don't put the rate here! Otherwise it resets the rate & channels set below, as shown by:  cat /proc/asound/card0/pcm0p/sub0/<wbr>hw_params<br>
                slave {<br>
                        # 2 for stereo, 6 for surround51, 8 for surround71<br>
                        channels 2<br>
                        pcm {<br>
                                format S16_LE<br>
                                #format S32_LE<br>
<br>
                                #rate 44100<br>
                                rate 48000<br>
<br>
                                # <a href="http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html" rel="noreferrer" target="_blank">http://www.alsa-project.org/<wbr>alsa-doc/alsa-lib/pcm_plugins.<wbr>html</a><br>
                                # Maybe helps<br>
                                nonblock true<br>
                                type hw<br>
                                card "PCH"<br>
                                device 0<br>
                                subdevice 0<br>
                        }<br>
<br>
                        # mplayer2 chooses 1024<br>
                        # period_size 512 with buffer_size 16384 stops crackling in xmame<br>
                        # 320 breaks flash - <a href="https://bbs.archlinux.org/viewtopic.php?id=129458" rel="noreferrer" target="_blank">https://bbs.archlinux.org/<wbr>viewtopic.php?id=129458</a><br>
                        #period_size 512<br>
                        period_size 1024<br>
<br>
                        # 4096 might make sound crackle<br>
                        # mplayer2 chooses 8192. Half-Life 2 chooses 16384.<br>
                        # If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=<wbr>2048<br>
                        buffer_size 8192<br>
                }<br>
        }<br>
        capture.pcm "schneeball"<br>
}<br>
<br>
libvirt xml snippets:<br>
<br>
    <sound model='ich9'><br>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/><br>
    </sound><br>
    ...<br>
    <qemu:env name='QEMU_AUDIO_DRV' value='alsa'/><br>
    <qemu:env name='QEMU_DAC_FIXED_SETTINGS' value='0'/><br>
    <qemu:env name='QEMU_DAC_TRY_POLL' value='0'/><br>
    <qemu:env name='QEMU_DAC_TIMER_PERIOD' value='0'/><br>
    <qemu:env name='QEMU_DAC_BUFFER_SIZE' value='0'/><br>
    <qemu:env name='QEMU_DAC_PERIOD_SIZE' value='0'/><br>
    <qemu:env name='QEMU_DAC_DEV' value='dmixed'/><br>
<br>
______________________________<wbr>_________________<br>
libvirt-users mailing list<br>
<a href="mailto:libvirt-users@redhat.com">libvirt-users@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvirt-users" rel="noreferrer" target="_blank">https://www.redhat.com/<wbr>mailman/listinfo/libvirt-users</a></blockquote></div><br></div></div>