cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.65k stars 102 forks source link

Audio Device for Linux VMs #795

Closed adit-s closed 2 months ago

adit-s commented 2 months ago

Hello. I came across tart.run a few days ago and just started to experiment with it. So far, it works very well and the performance is so good, it feels almost like bare metal. I've gone through the docs and github issues and discussions, but couldn't figure it out so thought I'd ask here: Is there a way to add an audio device to a linux VM (either from one of the pre-built images (like ghcr.io/cirruslabs/ubuntu:latest) or when creating from scratch (https://tart.run/integrations/vm-management/)?

Basically, I'd like to try and run a full desktop with sound. Everything else seems to work great following the standard steps except for the audio.

I'm not familiar with the packer plugin and not really sure if it's necessary for this request.

Thanks in advance.

Environment: tart version 2.9.0 Macbook Pro M1 with Sonoma 14.4.1

fkorotkov commented 2 months ago

@adit-s which distribution do you use? Tart provides virtio audio devices.

adit-s commented 2 months ago

@fkorotkov I've tried with two:

I started with the pre-built image (not sure if that's the right terminology) - ghcr.io/cirruslabs/ubuntu:latest (which is Ubuntu 22.04) It didn't work so I tried with a manual installation using Ubuntu 23.10.

Hovering over the speaker it says "no output or input devices found."

Screenshots from both are attached. Screenshot 2024-04-22 at 11 31 01 PM Screenshot 2024-04-22 at 11 35 27 PM

adit-s commented 2 months ago

@fkorotkov I found this link which I think describes how to correct the issue. It says "To enable VIRTIO sound support in Linux guests, configure sound support in the kernel using the CONFIG_SND_VIRTIO kernel parameter." and describes the steps.

I don't have a good enough understanding of the subject to know how to apply it to my issue, but I hope it can help you to resolve the issue.

Thanks, Adit

edigaryev commented 2 months ago

Ubuntu 22.04.4 LTS already comes with this VirtIO sound module, however, it doesn't really work and the sound levels are jumping around a specific constant point:

Screenshot 2024-04-24 at 22 42 08

I'm not sure where you've obtained the 23.10 for arm64, but you can verify that you have the module either by going to Settings → Sound or by running the following commands:

$ grep CONFIG_SND_VIRTIO /boot/config-$(uname -r)
CONFIG_SND_VIRTIO=m
$ lsmod | grep '^virtio_snd'
virtio_snd             36864  4
adit-s commented 2 months ago

Hello @edigaryev. Thanks for getting back to me. I downloaded Ubuntu 23.10 for arm from here. I gave up trying with 23.10 to stick with 22.04 LTS. In trying to find a solution, it does look like the virtio package is included in the 5.15.0-105-generic (22.04 LTS) kernel.

Running the same commands on my installation of 22.04 gives the following results:

$ grep CONFIG_SND_VIRTIO /boot/config-$(uname -r)
CONFIG_SND_VIRTIO=m
$ lsmod | grep '^virtio_snd'
virtio_snd             40960  2

Iny my case, there isn't any sound. I'm not sure, but it seems like it may be an issue with how the sound card is configured? I don't really have any other ideas on how to get the sound working. If you do, I'd appreciate it if you can suggest them.

Thanks, Adit

adit-s commented 2 months ago

@edigaryev I thought I'd try with another arm distribution to see if they can better handle the virtio sound; The Fedora image (from here) is in a .raw.xz format, and the Manjaro image (from here) is in a .img.xz format. I can uncompress them - can you tell me how to use the associated .raw and .img files to manually create a tart VM?

Thanks.

edigaryev commented 2 months ago

Something like this should work:

tart create --linux fedora
wget https://download.fedoraproject.org/pub/fedora/linux/releases/40/Workstation/aarch64/images/Fedora-Workstation-40-1.14.aarch64.raw.xz
unxz Fedora-Workstation-40-1.14.aarch64.raw
tart run --disk Fedora-Workstation-40-1.14.aarch64.raw fedora

The same approach for Manjaro.

adit-s commented 2 months ago

With Manjaro, I get the following error:

adit@m1p tart.app % tart create manjarotest --linux
adit@m1p tart.app % tart run --disk ~/Downloads/Manjaro-ARM-kde-plasma-generic-23.02.img manjarotest
guest has stopped the virtual machine

The Fedora Workstation v40 runs, but I get the same issue with the sound. The microphone input seems to map correctly to the virtio device, but output device still shows a "dummy" output. I'm not sure what to do as a next step?

Screenshot 2024-04-25 at 11 35 15 AM

The output from the previous commands is also attached. It seems the virtio_snd is there...

Screenshot 2024-04-25 at 11 43 30 AM

fkorotkov commented 2 months ago

Seems like the issue is not with Tart but rather with particular distributions of Linux and support of virtio audio devices. Closing the issue.

adit-s commented 2 months ago

I agree it's not an issue with tart, but it would be nice if there was a way to make it work. I'm sure it would help quite a few others as well.

Thanks for your help and guidance. tart is very good!

adit-s commented 2 months ago

I found a working solution. It's listed here for anyone else who comes across this post. Note: It only worked with Ubuntu 23.10 for me. 22.04 and 24.04 did not work.

I installed the Ubuntu 23.10 arm server image following the standard tart installation procedure. Then installed the KDE desktop environment (sudo apt install kde-standard). In the desktop, installed pavucontrol (sudo apt install pavucontrol). Start the Pulse Audio Volume Control app from the desktop and under the configuration tab choose the 'Pro Audio' profile.

The sound works well for audio streams and video. It's not choppy or breaking like in some of the other setups.

I hope this helps.

marcomastri commented 3 weeks ago

I tried the suggestion on this forum post (with a Fedora VM). For a while I thought the problem was gone, but playing a video on youtube still gives stuttering after some minutes of playback. Still, maybe it’s a step in the right direction.