Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

So You Want a Song on Your Sega?

Hey Stoat Pals! I've been quiet for a while because my day job has involved a lot of really intense coding lately and I haven't had the gusto to also code for fun. However, I'm not dead, I do have projects in progress, and I do so enjoy talking to those wonderful, cool people who actually care what I have to say :) I still don't particularly want to code, but I do think it's time to write my long-awaited post on putting music in SGDK. I call it:

So You Want a Song on Your Sega: An Arduous Journey

Here we go.

You've decided to make a Mega Drive/Genesis game. Awesome! Check out SGDK! It makes writing a game on MD about as easy as writing a game on anything else!*

Cool! The first part of making a game is finding some assets. Easy! You'll just hop over to opengameart.org or something, find some .pngs, fidget with colors, and you're off to the races because SGDK accepts .pngs, and even cuts them into tiles and animates them for you.

Here's a .png of a cute snail, for example, that I grabbed from "Flatlander" at https://opengameart.org/content/snail, modified a bit, and in a few minutes we have an asset that can crawl across the screen like a real-life video game cartoon snail.


Adorable.

You find the background tileset just as easily (after all, it's just a .png too). Now it's time for music. 

You read through https://github.com/Stephane-D/SGDK/blob/master/bin/rescomp.txt, the authoritative source for encoding assets in SGDK. You enthusiastically skim the file looking for anything resembling "music" and arrive at the "XGM" section. Then you read the saddest passage you'll ever see in a technical manual:

file            path of the .vgm or .xgm music file to convert to binary data array

You Google frantically! Surely, somebody on The Internet has, at some point, posted a .vgm or .xgm file you could use! Alas, if anybody has ever made a .vgm file, they did not deign to share it with you :( Unless of course, you want to just rip off commercial music. You can, of course, find all of that in .vgm.

What Strange Encoding

Well, maybe you can learn about one of these two formats and make them yourself. You're optimistic! Okay, let's crush that hope systematically:

Defeat 1: .xgm Isn't Real

Well, it's kind of real. I believe it's the native format for SGDK's "XGM" driver. However, nobody in history** has ever written an .xgm file directly. SGDK just converts .vgm files to .xgm files. So I guess that leaves us with .vgm.

Defeat 2: You Can't Just Make a .vgm File

Did you know that that the MD's sound hardware is pretty weird? Modern sound cards in consumer electronics just play samples: the developer just makes a sound in real life, digitizes it, and then it sounds exactly the same to the listener. You want a real orchestra to score your modern*** video game, sure, no problem: 

Well, back in 1988 that would have been prohibitively expensive. So the MD isn't optimized for samples; rather, it generates sounds using two synthesizers:

  1. The Yamaha YM 2612, a 6-channel FM synth
  2. The TI SNA76489, a 4-channel PCM synth

To learn more, check out the "Audio" section of https://www.copetti.org/writings/consoles/mega-drive-genesis/. Mr Copetti does a better job of explaining everything than I could. I'll elucidate a few points though.

  1. For an extremely talented sound programmer, this configuration of two synths can sound real good (and quite distinct from other instrumentation) 
  2. The internal data structure of MD music is extremely different from the data structure of sampled music (CD, .mp3, .wav file, etc). Sampled music is, at its core, just a sequence of amplitudes sampled over time. It's such a simple idea that it can be encoded in the topology of a physical object (ie a record). MD music, in contrast, is a complex computer program that must, with perfect timing, instruct each of the 10 channels about the shape, frequency, amplitude, and wave form that they are to play. Think of MD-formatted sound like the conductor of an orchestra that must not only tell each of her musicians what to play, but must also tell them which instruments to play at which time. That complex format is what a .vgm file is.

So I Can't Just Convert An .mp3 to .vgm

Hahaha. No. Well, actually, kind of. The MD is capable of playing low-quality sampled audio. For instance, the famous "Rise from your grave!" in Altered Beast, or this accordion solo:

The catch is that sampled music takes a lot of space. Back when cartridges were 1 Megabyte, developers could squeeze a few seconds of samples on a cartridge and had to do the rest with synth. In 2024, we can at least use the maximum rom size (a whopping 4 Megabytes!) and that's enough to fit something like 2-3 minutes of sampled music in a game. At present, sampled music is my preferred approach because it's easy. It sounds... okay: 

There Must Surely Be A Better Way!

Well, there is a different file format on the Internet that people share and you can occasionally license. It's something of a conceptual cousin of .vgm:

Really? Midi Is What We're Going With?

I'm afraid so. There is a limited, abandoned tool that converts .mid into .vgm. (https://vgmrips.net/forum/viewtopic.php?t=1929). Even though it hasn't been touched in a decade, I'm still grateful to the author (goes by ValleyBell) to make such a niche piece of software. Results are mixed for two reasons:

  1. Each .midi voice needs to be translated to an FM synth equivalent. It's never going to sound exactly as intended, and I don't like most of the default patches provided. You can, at least, map every Midi voice to vibraphone and that sounds okay.
  2. The MD's YM 2612 can only play 6 notes simultaneously, where as Midi supports a lot more simultaneous notes. If your source .midi has a complex composition, the MD version is going to be missing a lot of notes.

This approach works well enough with simple compositions. For instance, Stoat XV plays a classical piece that was originally string instruments, and that sounds great (after, of course, all the voices are translated to vibraphone)


I'm less happy with complex compositions. For instance, the Snail game is meant to use this track from the amazing and free "Ultimate Midi Pack" 

I converted it to VGM, changed a bunch of instruments to less ear-splitting instruments, and the result is okay but it's missing much of the force (and notes) of the original composition:

Okay, But How Would an Actual Composer Do It? 

An actual composer would use one of two specialized trackers: Furnace or Deflemask, both of which export to .vgm. I've used Furnace a bit and it's nice, though music composition intimidates me because I'm a real good coder but I'm not a composer.

Call To Action

I see a beautiful future in which talented musicians share .vgm files the same way they share .mp3 files today. Whether you're interested in creative expression, fame****, or cash***** I encourage you to share your .vgms with the world! Making music for MD is a really interesting, fun creative restriction where the results can sound really neat, plus appear in a cool retro game!

As a personal note, if you have some real good .vgms lying around just looking for a matching game, contact me and we can talk ;)

Footnotes

* As long as you have a university-level understanding of C, but doesn't everybody?

** This might be hyperbole but it probably isn't.

*** By "modern" I mean circa 1994.

**** In a very niche community.

***** Not very much money, but maybe a coffee or two.

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.