[PR #13471] [MERGED] Reimplement DECPS using DirectSound in place of MIDI #29566

Open
opened 2026-01-31 09:35:40 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/13471
Author: @j4james
Created: 7/9/2022
Status: Merged
Merged: 7/14/2022
Merged by: @undefined

Base: mainHead: decps-using-directsound


📝 Commits (3)

  • d416bc5 Reimplement the MidiAudio class using DirectSound.
  • 278e960 Remove the unused Midi library and DECPSViaMidiPlayer feature.
  • 78bd40f Add expected words to spellbot dictionary.

📊 Changes

7 files changed (+108 additions, -71 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+14 -0)
📝 src/audio/midi/MidiAudio.cpp (+79 -52)
📝 src/audio/midi/MidiAudio.hpp (+11 -1)
📝 src/cascadia/TerminalControl/ControlCore.cpp (+2 -1)
📝 src/cascadia/TerminalControl/TerminalControlLib.vcxproj (+0 -4)
📝 src/features.xml (+0 -12)
📝 src/host/consoleInformation.cpp (+2 -1)

📄 Description

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

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/13471 **Author:** [@j4james](https://github.com/j4james) **Created:** 7/9/2022 **Status:** ✅ Merged **Merged:** 7/14/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `decps-using-directsound` --- ### 📝 Commits (3) - [`d416bc5`](https://github.com/microsoft/terminal/commit/d416bc5f3dd4a2cc04a016491d3b482ee90714db) Reimplement the MidiAudio class using DirectSound. - [`278e960`](https://github.com/microsoft/terminal/commit/278e96098c213c8918955dcca05329dced5b3e8f) Remove the unused Midi library and DECPSViaMidiPlayer feature. - [`78bd40f`](https://github.com/microsoft/terminal/commit/78bd40f6ecad5e901dfdf9a84f5f91e9d61b3d9a) Add expected words to spellbot dictionary. ### 📊 Changes **7 files changed** (+108 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+14 -0) 📝 `src/audio/midi/MidiAudio.cpp` (+79 -52) 📝 `src/audio/midi/MidiAudio.hpp` (+11 -1) 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+2 -1) 📝 `src/cascadia/TerminalControl/TerminalControlLib.vcxproj` (+0 -4) 📝 `src/features.xml` (+0 -12) 📝 `src/host/consoleInformation.cpp` (+2 -1) </details> ### 📄 Description ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:35:40 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#29566