Connecting ALSA from a VM to the host?

24 views
Skip to first unread message

Rich Morin

unread,
Dec 12, 2019, 9:33:12 PM12/12/19
to vagra...@googlegroups.com
Having switched from OSS to ALSA, I've made some progress, but I'm still not getting sound. By way of background, I'm doing my development and testing on a MacBook Air, running macOS High Sierra (10.13.6). As I recently posted on the ALSA list:

> I've successfully built a VirtualBox instance, based on Ubuntu, for use under Vagrant. Now I'd like to set up ALSA to use the host's audio output system. Making things more complicated, the host could be running Linux, macOS, Windows, or ???

I reworked my Vagrantfile to incorporate some ideas from Christoph Neumann's vagrant-audio Vagrantfile (in https://github.com/christoph-neumann/vagrant-audio). For details, see this gist:

https://gist.github.com/RichMorin/dc9138962c19c205697bea23cce5134c

After building the VM, I can SSH into it via `vagrant ssh`.

If I then run `speaker-test`, the program prints out some promising text and then hangs:

vagrant@vagrant:~$ speaker-test
speaker-test 1.1.8

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 69 to 17832
Period size range from 34 to 8917
Using max buffer size 17832
Periods = 4
was set period_size = 4458
was set buffer_size = 17832
0 - Front Left

And, if I do `aplay -L`, I get:

vagrant@vagrant:~$ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default
sysdefault:CARD=Intel
HDA Intel, STAC9221 A1 Analog
Default Audio Device
front:CARD=Intel,DEV=0
HDA Intel, STAC9221 A1 Analog
Front speakers
...

Helpful clues, comments, and suggestions are solicited.

-r

Rich Morin

unread,
Dec 13, 2019, 11:41:16 AM12/13/19
to vagra...@googlegroups.com
On the ALSA list, Clemens Ladisch gave me this hint:

> You have to configure the VM to provide a (virtual) sound hardware device
> (https://www.virtualbox.org/manual/ch03.html#settings-audio), or to pass
> through a USB audio device from the host.


That section (quoted below) lists several settings that need to be made before things will work. Problem is, I don't know how to check these in the Vagrant environment. Help?

-r

> The Audio section in a virtual machine's Settings window determines whether the VM will detect a connected sound card, and if the audio output should be played on the host system.
>
> To enable audio for a guest, select the Enable Audio check box. The following settings are available:
>
> Host Audio Driver: The audio driver that Oracle VM VirtualBox uses on the host. On a Linux host, depending on your host configuration, you can select between the OSS, ALSA, or the PulseAudio subsystem. On newer Linux distributions, the PulseAudio subsystem is preferred.
>
> Only OSS is supported on Oracle Solaris hosts. The Oracle Solaris Audio audio backend is no longer supported on Oracle Solaris hosts.
>
> Audio Controller: You can choose between the emulation of an Intel AC'97 controller, an Intel HD Audio controller, or a SoundBlaster 16 card.
>
> Enable Audio Output: Enables audio output only for the VM.
>
> Enable Audio Input: Enables audio input only for the VM.


Eric Zuck

unread,
Dec 13, 2019, 1:06:47 PM12/13/19
to vagra...@googlegroups.com
On 2019-12-13 11:41 a.m., Rich Morin wrote:
> On the ALSA list, Clemens Ladisch gave me this hint:
>
>> You have to configure the VM to provide a (virtual) sound hardware device
>> (https://www.virtualbox.org/manual/ch03.html#settings-audio), or to pass
>> through a USB audio device from the host.
>
> That section (quoted below) lists several settings that need to be made before things will work. Problem is, I don't know how to check these in the Vagrant environment. Help?
I don't have a mac, but this worked for me:
In Vagrantfile, add the following:
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--audio", "alsa"]
    vb.customize ["modifyvm", :id, "--audioout", "on"]
  end

The relevant documentation:
https://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvm-general

https://www.vagrantup.com/docs/virtualbox/configuration.html#vboxmanage-customizations

Hope this works for you :)
-EricZ

Rich Morin

unread,
Dec 14, 2019, 12:53:45 AM12/14/19
to vagra...@googlegroups.com
Thanks, Eric! It turns out that all I needed to do was add this magic line:

> vb.customize ["modifyvm", :id, "--audioout", "on"]

FYI, my current Vagrantfile look like this:

https://gist.github.com/RichMorin/dc9138962c19c205697bea23cce5134c

-r

Alvaro Miranda Aguilera

unread,
Dec 16, 2019, 2:59:22 PM12/16/19
to vagra...@googlegroups.com
vagrant is just a wrapper

once the vm has been created, you can stop the vm with vagrant halt

then go to the VM settings in virtualbox and add whatever you think is needed ie a sound card

once this is done, turn the VM on and test the sound.

as long the virtualbox guest additions are installed and you have some sort of mixer on the vm to adjust audio it should work

then you can either export the VM and have it as a new base box

or

you can use VBoxManage to add the sound card you need.

you can customize the box like this


alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/84D2FD0F-EE3E-4082-AB60-30C84DAFDFF4%40cfcl.com.


--
Alvaro

Rich Morin

unread,
Dec 16, 2019, 3:23:34 PM12/16/19
to vagra...@googlegroups.com
> On Dec 16, 2019, at 11:59, Alvaro Miranda Aguilera <kik...@gmail.com> wrote:
>
> ... then go to the VM settings in virtualbox and ...

I'm using Vagrant because I want to have a terminal-based user interface both for myself and my users (who may be blind or visually impaired). So, the "obvious" workaround of using VirtualBox directly is not a satisfactory option.
This link led me to https://www.virtualbox.org/manual/ch08.html, which seems quite promising.

-r

Alvaro Miranda Aguilera

unread,
Dec 16, 2019, 3:45:15 PM12/16/19
to vagra...@googlegroups.com
hello

you need to do that just once to see what are the settings you need

then you can codify what is needed as part of the vagrantfile

make sense ?

i was suggesting the first step, make it work

then we can review how to codify / make it part of the vagrantfile

alvaro
Reply all
Reply to author
Forward
0 new messages