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

We might need another dependency for MIDI support #13252

Closed
zadjii-msft opened this issue Jun 8, 2022 · 10 comments · Fixed by #13471
Closed

We might need another dependency for MIDI support #13252

zadjii-msft opened this issue Jun 8, 2022 · 10 comments · Fixed by #13471
Labels
Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@zadjii-msft
Copy link
Member

zadjii-msft commented Jun 8, 2022

~Promoted from a Teams thread. Tracking here so we don't lose it. ~

Notes from @DHowett:

@j4james handled this for us, by adding a package dependency on GmDls. We need to make sure that when Terminal is installed, users get access to it. I am somewhat concerned about what this means for Inbox Terminal, though: It costs us 3MB on disk which will be aggressively counted against us by Windows Perf Gates
I looked at the code that loads gm.dls and it seems like it was never updated to consider Centennial apps. If a process has "strong identity" (a package), it forces a catalog enumeration to find the GmDls package. We might be able to defray the cost of pulling in a second copy of gm.dls to the Windows image by giving it the ability to "fail over" to the system32 one.

@zadjii-msft zadjii-msft added Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. Priority-0 Bugs that we consider release-blocking/recall-class (P0) labels Jun 8, 2022
@zadjii-msft zadjii-msft added this to the Terminal v1.15 milestone Jun 8, 2022
@ghost ghost added the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Jun 8, 2022
@j4james
Copy link
Collaborator

j4james commented Jun 9, 2022

Btw, if you want to revert PR #13208 until we can figure out a solution for this, that's fine by me. It's not exactly an essential feature.

And if in turns out that we can't use the MIDI API, I could try and come up with another way to produce the sound. I just chose MIDI because it seemed easiest.

@zadjii-msft zadjii-msft removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Jun 9, 2022
@zadjii-msft
Copy link
Member Author

Plan of record right now is to stash this behind velocity, so it only ships in Preview (and critically, not in the OS-side build). That way we can get a little longer window on figuring out how we want to resolve this.

@phil-blain
Copy link

Hi, I just tried to compile Terminal from 4e20a86 and installing it from a loose package as detailed in https://github.com/microsoft/terminal/blob/main/doc/building.md.

I can confirm that installing the loose package fails for me with (pardon my French!)

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF3, Échec des mises à jour, de la dépendance ou de la validation des conflits du package.
Windows ne peut pas installer le package WindowsTerminalDev_0.0.1.0_x64__8wekyb3d8bbwe, car ce package dépend d’une infrastructure qui n’a pas pu être trouvée. Indiquez
l’infrastructure «Microsoft.Midi.GmDls» publiée par «CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US», avec une architecture neutre ou de
processeur x64 et la version minimale 1.0.0.0, en plus de ce package à installer. Les infrastructures avec le nom «Microsoft.Midi.GmDls» installées actuellement sont
Windows ne peut pas installer le package WindowsTerminalDev_0.0.1.0_x64__8wekyb3d8bbwe, car ce package dépend d’une infrastructure qui n’a pas pu être trouvée. Indiquez
l’infrastructure «Microsoft.Midi.GmDls» publiée par «CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US», avec une architecture neutre ou de
processeur x64 et la version minimale 1.0.0.0, en plus de ce package à installer. Les infrastructures avec le nom «Microsoft.Midi.GmDls» installées actuellement sont: {}
NOTE: For additional information, look for [ActivityId] 92e6da5a-7c16-0002-9b44-ea92167cd801 in the Event Log or use the command line Get-AppPackageLog -ActivityID
92e6da5a-7c16-0002-9b44-ea92167cd801
At line:1 char:1
+ Add-AppxPackage -Path ..\loose\AppxManifest.xml -Register -ForceUpdat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\me...ppxManifest.xml:String) [Add-AppxPackage], IOException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

I'm currently building from 9dca6c27eeeb4371c87cdc553d01b8876d028d21^ (i.e. 7dbe741) just to confirm that 9dca6c2 is indeed is the culprit, but since I found this issue in the meantime I'm pretty sure now :P

@DHowett
Copy link
Member

DHowett commented Jun 9, 2022

Curious. That package should be available on your system, @phil-blain, somewhere in C:\Program Files (x86). It comes with the Windows SDK or one of the extension SDKs that ships with Visual Studio...

@phil-blain
Copy link

It is indeed in C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.Midi.GmDls\10.0.22000.0. Maybe the installation does not work because it is not listed as a PackageDependency in the genereated AppxManifest.xml ?

DHowett added a commit that referenced this issue Jun 9, 2022
* conhost requires an additional dependency in Windows, which might
  cause us trouble in WPG
* Terminal requires an additional *package* dependency, which *will*
  cause us trouble in WPG (since GmDls is about 3MB)

I chose to scope the feature checks to MidiOut directly, as I wanted to
keep the delay behavior in MidiAudio::PlayNote. This is negotiable.

References #13252
@zadjii-msft
Copy link
Member Author

With #13258 merged, I'm moving this out to 1.16

@DHowett DHowett removed the Severity-Blocking We won't ship a release like this! No-siree. label Jul 5, 2022
@j4james
Copy link
Collaborator

j4james commented Jul 7, 2022

@DHowett FYI, I've been playing around with an alternate implementation that uses DirectSound to generate the audio in place of Midi. Would it be worthwhile submitting a PR with that change, or do you have other plans for resolving this?

@DHowett
Copy link
Member

DHowett commented Jul 8, 2022

Huh, that seems like it might be a good way out of this! We wouldn't need to ship another package dependency...

I don't have any concrete plans that will resolve the GmDls package in the near future. My plans are more like, "Fix this in Windows 18 by getting the owner to let me move around some of their code," which would never be serviceable to earlier versions of Windows. :(

@j4james
Copy link
Collaborator

j4james commented Jul 8, 2022

which would never be serviceable to earlier versions of Windows. :(

OK, that's a deciding factor for me. I'll try and put together a PR this weekend.

@ghost ghost added the In-PR This issue has a related PR label Jul 9, 2022
@ghost ghost closed this as completed in #13471 Jul 14, 2022
ghost pushed a commit that referenced this issue Jul 14, 2022
## Summary of the Pull Request

The original `DECPS` implementation made use of the Windows MIDI APIs to
generate the sound, but that required a 3MB package dependency for the
GS wavetable DLS. This PR reimplements the `MidiAudio` class using
`DirectSound`, so we can avoid that dependency.

## References

The original `DECPS` implementation was added in PR #13208, but was
hidden behind a velocity flag in #13258.

## PR Checklist
* [x] Closes #13252
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [x] I've discussed this with core contributors already. Issue number
where discussion took place: #13252

## Detailed Description of the Pull Request / Additional comments

The way it works is by creating a sound buffer with a single triangle
wave that is played in a loop. We generate different notes simply by
adjusting the frequency at which that buffer is played.

When we need a note to end, we just set the volume to its minimum value
rather than stopping the buffer. If we don't do that, the repeated
starting and stopping tends to produce a lot of static in the output. We
also use two buffers, which we alternate between notes, as another way
to reduce that static.

One other thing worth mentioning is the handling of the buffer position.
At the end of each note we save the current position, and then use an
offset from that position when starting the following note. This helps
produce a clearer separation between tones when repeating sequences of
the same note.

In an ideal world, we should really have something like an attack-decay-
sustain-release envelope for each note, but the above hack seems to work
reasonably well, and keeps the implementation simple.

## Validation Steps Performed

I've manually tested both conhost and Terminal with the sample tunes
listed in issue #8687, as well as a couple of games that I have which
make use of `DECPS` sound effects.
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Jul 14, 2022
DHowett pushed a commit that referenced this issue Jul 19, 2022
## Summary of the Pull Request

The original `DECPS` implementation made use of the Windows MIDI APIs to
generate the sound, but that required a 3MB package dependency for the
GS wavetable DLS. This PR reimplements the `MidiAudio` class using
`DirectSound`, so we can avoid that dependency.

## References

The original `DECPS` implementation was added in PR #13208, but was
hidden behind a velocity flag in #13258.

## PR Checklist
* [x] Closes #13252
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [x] I've discussed this with core contributors already. Issue number
where discussion took place: #13252

## Detailed Description of the Pull Request / Additional comments

The way it works is by creating a sound buffer with a single triangle
wave that is played in a loop. We generate different notes simply by
adjusting the frequency at which that buffer is played.

When we need a note to end, we just set the volume to its minimum value
rather than stopping the buffer. If we don't do that, the repeated
starting and stopping tends to produce a lot of static in the output. We
also use two buffers, which we alternate between notes, as another way
to reduce that static.

One other thing worth mentioning is the handling of the buffer position.
At the end of each note we save the current position, and then use an
offset from that position when starting the following note. This helps
produce a clearer separation between tones when repeating sequences of
the same note.

In an ideal world, we should really have something like an attack-decay-
sustain-release envelope for each note, but the above hack seems to work
reasonably well, and keeps the implementation simple.

## Validation Steps Performed

I've manually tested both conhost and Terminal with the sample tunes
listed in issue #8687, as well as a couple of games that I have which
make use of `DECPS` sound effects.

(cherry picked from commit bc79867)
Service-Card-Id: 84270205
Service-Version: 1.15
@ghost
Copy link

ghost commented Aug 5, 2022

🎉This issue was addressed in #13471, which has now been successfully released as Windows Terminal Preview v1.15.200.:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants