Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual sound device on Windows Instance #2528

Closed
cmaughan opened this issue Jan 22, 2021 · 15 comments
Closed

Virtual sound device on Windows Instance #2528

cmaughan opened this issue Jan 22, 2021 · 15 comments
Assignees
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows question Further information is requested

Comments

@cmaughan
Copy link

Description
I'm writing tests for Sonic Pi, using Github Actions.

On Linux I can do 'jackd -d dummy &' to get a virtual audio device.
On Mac, Soundflower is automatically installed (a virtual audio device)
But I'm stuck on Windows. Is there a way for my github action to run a test which finds an audio device on a windows instance? It doesn't need to make a sound, obviously, just register as an audio device that the software can connect to.

Question, Bug, or Feature?:
Question

Virtual environments affected

  • [* ] Windows Server 2016 R2
  • [ *] Windows Server 2019

Expected behavior
Some kind of valid sound device is installed

Actual behavior
No sound device is found

Repro steps
Launch an executable as part of an action that requires a sound device (virtual or real).

@al-cheb al-cheb added investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows labels Jan 25, 2021
@al-cheb al-cheb self-assigned this Jan 25, 2021
@al-cheb al-cheb added Area: Image administration question Further information is requested and removed needs triage labels Jan 25, 2021
@al-cheb
Copy link
Contributor

al-cheb commented Jan 25, 2021

Hello, @cmaughan
Could you please try to install in runtime [https://github.com/duncanthrax/scream]?

jobs:
  compile:
    runs-on: windows-2019
    steps:
      - name: Audio device
        run: Get-CimInstance Win32_SoundDevice | fl *
      - name: Install Scream
        shell: powershell
        run: |
          Start-Service audio*
          Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.6/Scream3.6.zip -OutFile C:\Scream3.6.zip
          Extract-7Zip -Path C:\Scream3.6.zip -DestinationPath C:\Scream
          $cert = (Get-AuthenticodeSignature C:\Scream\Install\driver\Scream.sys).SignerCertificate
          $store = [System.Security.Cryptography.X509Certificates.X509Store]::new("TrustedPublisher", "LocalMachine")
          $store.Open("ReadWrite")
          $store.Add($cert)
          $store.Close()
          cd C:\Scream\Install\driver
          C:\Scream\Install\helpers\devcon install Scream.inf *Scream
      - name: Audio device
        run: Get-CimInstance Win32_SoundDevice | fl *

image

@cmaughan
Copy link
Author

This works great :) Thanks so much for the effort; I hope it didn't take too long!
https://github.com/cmaughan/sonic-pi/runs/1764226203?check_suite_focus=true#step:22:217

@al-cheb al-cheb closed this as completed Feb 2, 2021
@dechamps
Copy link

dechamps commented Oct 5, 2021

@al-cheb Thanks for this snippet, it works great. I took the liberty of simplifying it a bit:

      - name: Install Scream
        shell: powershell
        run: |
          Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.8/Scream3.8.zip -OutFile Scream3.8.zip
          Expand-Archive -Path Scream3.8.zip -DestinationPath Scream
          Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher 
          Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream

One thing I noticed is that Scream only provides an output (render) audio device. I wonder if we could use a different driver to provide an input (capture) device as well.

@larsoner
Copy link

larsoner commented Feb 12, 2022

@dechamps I use VBCable in the Windows part of sound-ci-helpers (which I use by running powershell sound-ci-helpers/windows/setup_sound.ps1 on Azure after a clone)

https://github.com/LABSN/sound-ci-helpers

I think It creates an input and an output device:

   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 CABLE Output (VB-Audio Virtual , MME (2 in, 0 out)
   2 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  3 Speakers (VB-Audio Virtual Cabl, MME (0 in, 2 out)
...

Feel free to try it! I should probably make this a proper GitHub Action step, I don't think it would be too difficult!

@dechamps
Copy link

On the new windows-2022 environment (which is currently being rolled out as windows-latest - see #4856), workflows using audio devices might break because the Windows Audio engine is not started by default anymore. This can be remedied using the following step:

- run: net start audiosrv

@Gustl22
Copy link

Gustl22 commented Jul 25, 2023

@al-cheb can we revive the discussion? Scream cannot afford the certificates, which is more than understandable. GitHub as part of Microsoft may can contribute or support, so that audio testing can become available again on windows:
duncanthrax/scream#202 (comment)
Thank you :)

@larsoner
Copy link

@Gustl22 it looks like you are talking about driver code signing, whereas this issue is about setting up a virtual sound device on CIs (which does seem possible using two solutions mentioned above: #2528 (comment), #2528 (comment))

@Gustl22
Copy link

Gustl22 commented Jul 25, 2023

@larsoner #2528 (comment) is no solution (I'm pretty sure at least), it just is an additional step to let Scream add a virtual device, see this run.

And your mentioned action also fails, see this run.

Yes, it is not about the specific solution, but it is about a working solution supported by GH Actions.

@larsoner
Copy link

And your mentioned action also fails, see this run.

Should be fixed now, feel free to try again 👍 Hopefully it works for now (until GH officially supports something, if ever!)

@Gustl22
Copy link

Gustl22 commented Aug 14, 2023

Thanks for fixing @larsoner, but even in your solution you propose to use scream once, vb cable driver breaks.
For me, the issue is not solved here.

@al-cheb please reconsider opening again. How does Microsoft solve this problem internally for their tests? Are they using real sound cards for that? Thx.

lihop added a commit to lihop/godot-setup that referenced this issue Feb 11, 2024
Updates scream install script to a simpler version written by Etienne Dechamps in:
actions/runner-images#2528 (comment).
@dechamps
Copy link

Looks like the Scream-based solution stopped working at some point on windows-latest (windows-2022 20240514.3.0) - it hangs on the devcon step:

Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream

Device node created. Install is complete when drivers are installed...
Updating drivers for *Scream from …\Scream\Install\driver\x64\Scream.inf.
(…hangs forever…)

Same if I upgrade to latest Scream 4.0.

Example run: https://github.com/dechamps/FlexASIO/actions/runs/9238174920/job/25415967004

Not sure what broke it?

@dechamps
Copy link

It took some heroics, but I was able to capture a screenshot:

      - shell: powershell
        run: Install-Module -Name PShot -AcceptLicense -Force
      - shell: powershell
        run: |
          Import-Module -Name PShot
          Start-Job { Get-PShot -Directory . -Delay 30 }
          Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream
        continue-on-error: true
        timeout-minutes: 1
      - uses: actions/upload-artifact@v2
        with:
          path: 'PShot*'

The result:

PShot_20240526_091035

Looks like the Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher command is not sufficient for it to work anymore.

@dechamps
Copy link

And I guess this is why:

image

I found duncanthrax/scream#215 about this. Looks like it's not going to be fixed, so we're gonna have to find some way to work around this or use a different driver.

@dechamps
Copy link

…and here's how I worked around it:

      - run: 'Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/4.0/Scream4.0.zip -OutFile Scream4.0.zip'
      - run: 'Expand-Archive -Path Scream4.0.zip -DestinationPath Scream'
      # To work around https://github.com/duncanthrax/scream/issues/215, create our own self-signed certificate for the Scream driver.
      # makecert.exe insists on interactively asking the user for a password (sigh...), so use OpenSSL instead.
      # `-extensions v3_req` is a trick to make sure the resulting cert has basic constraint CA:FALSE (the default is CA:TRUE which is problematic here) without having to create an OpenSSL config file.
      - run: 'openssl req -batch -verbose -x509 -newkey rsa -keyout ScreamCertificate.pvk -out ScreamCertificate.cer -nodes -extensions v3_req'
      - run: 'openssl pkcs12 -export -nodes -in ScreamCertificate.cer -inkey ScreamCertificate.pvk -out ScreamCertificate.pfx -passout pass:'
      # This is just to make sure signtool.exe is in the PATH
      - uses: ilammy/msvc-dev-cmd@v1
      # Sign the driver with the self-signed certificate we just made.
      - run: 'signtool sign /v /fd SHA256 /f ScreamCertificate.pfx Scream\Install\driver\x64\Scream.cat'
      # Tell Windows to trust the self-signed certificate we just made.
      # (For some reason it has to be added to both stores for it to work.)
      - run: 'Import-Certificate -FilePath ScreamCertificate.cer -CertStoreLocation Cert:\LocalMachine\root'
      - run: 'Import-Certificate -FilePath ScreamCertificate.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher'
      # Finally, install the driver.
      - run: 'Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream'
        # For convenience, make sure we fail fast if for whatever reason the install gets blocked on some GUI prompt.
        timeout-minutes: 5

All good now: https://github.com/dechamps/FlexASIO/actions/runs/9242970185/job/25426485555

You'll then likely want to follow that with net start audiosrv for the Windows audio stack to actually work.

@NathanCheshire
Copy link

For anyone trying to do what I was doing, install a virtual sound device on macos, windows, and ubuntu (all latest), see this run which works for scream on windows and also the aforementioned as of the date of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Windows question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants