Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slopgs

A vibe-reimplementation of swmidi.sys, a.k.a. Microsoft GS Wavetable Synth (MSGS). There is very likely something like this by now—if it’s the case, I’m not surprised. I’m just throwing my hat in the ring here.

Do note, that this is not a decompilation. Its goal is not to compile a software driver 1:1, but to provide a portable implementation of The Canonical MIDI Sound™.

A demo is currently installed in my MIDI page.

1. Contributions

Human and LLM-assisted PRs welcome.

When submitting issues, use the compare-*.html tools to help.

2. How to work with this thing

2.1. Things to get

  1. A C compiler (tested: GCC) - compiling msgs-render tool.

  2. Clang - compiling msgs.wasm

  3. Asciidoc (optional) - compiling docs

  4. Python - running the probe-generator program.

  5. dist/gm.dls - from your C:\WINDOWS\system32

  6. field/*.mid - any real MIDI you want to test.

  7. field/*.flac - you ought to provide the reference renderings, counterpart to their .mid

2.2. Build

  1. Run make on the project root.

  2. Try exporting a track using dist/msgs-render dist/gm.dls your.mid 1 999999 your.wav

2.3. A/B testing

  1. Pick a real-world MIDI, and record it using Windows Media Player and the Stereo Mix, if available.

  2. Export that out as a FLAC with the same name as the MIDI (example: mylittlething.flac for mylittlething.mid) into field/

  3. Ensure you’ve run make dist/msgs.wasm.

  4. Edit dist/compare-field.html using a text editor:

     (() => {
       const STEMS = [
    +    "mylittlething",
    -    "onestop_extract",
    -    "serum_opening",
    -    "corridor",
    -    "CrystalOscillator",
    -    "eek_the",
    -    "flourish",
    -    "HueArme-Weekend",
    -    "Kot_and_A64-GENERAL_SERUM",
    -    "onestop",
    -    "Strobe-faffaeefafaefae",
    -    "town",
       ];
  5. Run a static-file web server off the project root:

    python -m http.server <PORT>
  6. Go to http://localhost:<PORT>/dist/compare-field.html. You should see a bunch of cards with whatever STEMS listed.

  7. Click Load and compare, and out pops a fancy spectrogram. You can zoom it, click it, play it, etc. There is also a waveform view, if you believe a problem is better illustrated there.

2.4. Probles

  1. artifacts/probe-results - record the artifacts/probes MIDIs as FLACs there.

  2. Run a static-file web server off the project root:

    python -m http.server <PORT>
  3. Go to http://localhost:<PORT>/dist/compare-probes.html.

3. A disclaimer

I can’t claim to:

  • have reverse-engineered it; the LLM did.

  • have coded it; the LLM also did.

  • call it "mine"; I did very little work here.

…​so I don’t think I can put a LICENSE on this. But I can claim to:

  • have directed it.

  • have curated the results.

  • have written this README, at least. I have a Compose key.

So can I say I discovered it? I don’t know. But what I do know is that I’ve wished for this thing for a while now. And now, I have it. And you can have it as well.

At least it can play GENERAL SERUM almost accurately…​

4. What’s reimplemented

swmidi.sys off Windows XP Service Pack 3: 5.1.2600.5512 (xpsp.080413-2108)

If possible, I might get a comparison with the version of the driver that shipped with Windows 98 and Windows 10. They’ll be compile-time conditionals.

5. Why…​

5.1. Why did you do this?

I had a weekend to spare. Facing this brave new world, I’ve experimented with LLMs—or maybe, just a specific LLM.

It had already done:

  • a disassembly…​ well, added rockets to it, anyway.

  • an entire GB emulator with everything that I ever wanted

and I thought it would be funny to implement something that Matt Montag mentioned in an e-mail to me once:

...it would be neat to someday add a full emulation of MSGS as a synth engine..

— Matt

Haha, yeah. I think an MSGS clone synth that works everywhere would be amazing.

— me

It is current year, and it’s now here.

Technology kind of scares me.

5.2. Why did you employ the resource-munchers?

After seeing what it can do, I’m sadly addicted to these things. Most people in my general vicinity very much understands why LLM sees so much usage now, but I still can’t help but to feel conflicted.

It helped speed up a disassembly effort and created the literal emulator of my dreams. This time, it helped another one of my dreams come true.

It actually kind of scares me.

6. How did you do this?

Initially I gave it:

  1. The actual thing, swmidi.sys.

  2. The gm.dls the thing was designed with.

  3. My page on MSGS, Furmilion’s MSGS research, and the BotB page on MIDI.

  4. My MIDI page, in which to replace.

  5. A plan, which said:

    1. Disassemble swmidi.sys and make a SPEC.md.

    2. From this SPEC.md, dispatch an agent that implements this as a C synthesizer, and give it a wasm build.

    3. Replace bg-sound.js on my page with an alternative minimal one that loads in this wasmized MSGS.

There were some probe midis it gave me. Some small sidequests to determine what the resampler is: kmixer, portcls, ks, sysaudio, which in the end didn’t really matter so long as the synth rendered to native 22050 Hz…​

I left the plan cycle on overnight and the first version was done. The sound was initially shaky. I didn’t record it in version control immediately, but every note didn’t stop. But it is recognizable as MSGS-derived.

There was so much it can only infer from code, but the road to making it MSGS rests on the listening side, and me pointing out where it can be improved.

From there it was a fine-tuning game. The 80% took like 3 hours. It’s the last 20%, the one that counts, that takes forever.

I feel like one of those ROM hackers faffing about emulator accuracy and rejecting "inaccurate emulators" from the outset regardless of whether or not said accuracy is even relevant.

By the way: all emulators are fantasy consoles! How "fantasy" they are differs to a degree :)

6.1. What I’m testing it on so far

  • My own boring midis

  • Kot & A64 - GENERAL SERUM

  • Strobe - faffaeefafaefae

  • HueArme - Weekend

  • furmillion’s unfinished Crystal Oscillator

  • flourish, town, onestop

About

Reimplementation of Microsoft GS Wavetable Synth (a.k.a MSGS a.k.a swmidi.sys)

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages