>> Modding - Sounding good <<
No, I'm not adding modding support to the game.
Back in days of yore, there were a couple of ways to get music into a game. The first relies on the computer to have a synthesiser chip. The most famous of these is probably the Comodore 64's SID chip. These are miniature hardware synthesisers. The computer itself does little to no work to acutally play music, it just says "play this note" and it's the chip's responsibility to go and find a way to replicate that note. This is what chiptunes are - tunes generated by the chips.
The other option is for the computer to play samples. These can be entirely synthesised, or recorded. They are then modified by the computer to be the correct pitch, and then played in the correct order.
Of course there is some overlap between the two, and as with anything, it's not such a clear line. The Game Boy for example is very much in the former camp, but at the same time, one of its four channels is able to play short samples. The Atari Jaguar kind of goes the other way. At least with the sound engine I'm using, U-235SE, it can play any samples you give it, within certain limitations of course. However, despite this fact, it does have a dedicated chip, Jerry, for handling this. The CPU does not do the mixing. Jerry is a programmable RISC, but it still sits somewhere in between a pure chiptune machine, and the sample-driven system which would become modern music authoring software.
In the previous attempt at this project, I approached Matias Sosa on fiverr to create a variation of Foundations, the main menu intro music for X4 Foundations. He did a great job, and I'm keen to use it in this iteration of the game development. When I added the file to the game, it jumped up to 1.5MB. Now, this might not seem like a massive size in 2025, but we're talking a cartridge games console from the early 90s. The absolute maximum size of the ROM could be 6MB. If the game is at 1.5MB with one music track, a handful of roughly laid out locations, and very little gameplay, then I'm doing something very wrong, or going to end up with big problems.
To explain the problem, we need to discuss the file format that the music track was delivered in. It is a 'mod file' - a tracker format used initially on the Amiga. Looking up the format, the short version is that there is a 1084 byte header, which is a fixed size regardless of the track. Then you have multiple 1024 byte patterns. In the example of Foundations, there are 10, making up the 60s of the track. Following that you have the instrument samples. The lengths of these are defined in the header. In the case of the track I was using, this was then a little over 1kb of unavoidable data, 10kb of song data, and then 850kb of instrument samples.
Matias has been amazing and helped strip this down. It is now a hair over 350kb, and I think we can get it further, but I'm less concerned about this at this point.
But what does this mean? 350kb for every minute of music in the game? I'll still run out quickly.
No. The actual song data is 10kb per minute of audio. The intention going forward would be to have a library of instruments which all tracks can use. This library can be added once, into ROM, and could even be compressed. At runtime this can then be copied into RAM, along with the song data and header. U-235 can then play the mod file from RAM rather than ROM. This will mean that I'll need to allocate enough memory for the rebuilt mod file in RAM, but it will mean that the ROM doesn't grow at a crazy rate, and I can fit a lot more music into the game!