Wednesday, January 10, 2018

Productivity!

So I decided to tackle the audio system and have that semi-implemented now. I ran into a few snags that aren't really show stoppers, but I had to take a side track this morning. In the game there are 20 sound effects that are called. Depending on the hardware you had back then, a sample was played. If you had a Sound-blaster, a digital VOC file was played. If you had Adlib, which didn't have a DAC to play samples, it fell back to hand-manipulated sound effects. If you just had the old squeaker speaker, a sample was shoved out via the timer.

The problem was all the digital samples were not convertible into something more contemporary. The .snd file for the squeaker speaker appeared to be raw PWM data. The Adlib used assembly to hand-make the sound effects, and the Sound-blaster VOC files have their own special problems. It seems that even though back in the day VOCs were ubiquitous, they were also proprietary. Creative labs never released the actual format. There are a few programs that can read VOC files, but the ones I have are packed and not readable, or covertable by any of my legacy software.

This is not a especially terrible thing. The samples are rips from the original 60's Star Trek and need to be replaced anyway. I know where each effect is played in the game so I can hunt some sounds that are more appropriate for the game.

The last pass I have is allowing me to fix up Nermal once and foe all, and support high resolutions. One of my core functions, the blitter, is super hacky and I now have an opportunity to fix that, and most of the other functions, once and for all.


The credits roll in glorious 1280x800 now :)


Tuesday, January 9, 2018

Filesystem Abstraction

It's cold up here...
So there is a new weather satellite that was recently launched by NOAA that is beyond anything we currently have up there. This one is in geosynchronous orbit and has a high-resolution infrared camera so you can see weather patterns at night. During few days of cold I took a look at it and realized why it was dipping down past freezing for the last week or so. I wish Canada would find a better way of invading us.

Bright and early I was back into the code. Now that I have a good idea of what is what. I'm not as terrified to move things around and change up the program outside of Nermal. I have a few major goals this time around. The first I want to reduce the number of dependencies. First I'm abstracting the filesystem through Allegro and making it as generic as possible. The back-end, which currently points to my hard drive can be swapped out for any other kind of file system. This will make porting the game to Android/iOS a lot easier as the filesystems in those environments are abstracted and sandboxed anyway. In the meantime Not only do I find myself able to get rid of old DOS/Windows functions, but some POSIX ones as well.

I'm also getting rid of the insecure string functions and replacing them with their secure _s counterparts. The difference between srtcpy() and strcpy_s() is that the secure ones requires me tell it how big of a string buffer is I'm using. This is to stop buffer overruns from happening. The good news is all the strings I'm running into so far are not dynamically created so I can just pass the new functions the length of the buffers directly.

The audio functions are proving to be a bit more complicated than I thought. I also had to re-render the opening theme to Ogg Vorbis. Looks like mp3 support was not implemented due to patents. It's only very recently that those have expired. Doesn't really matter, they all sound the same.

I'm hoping tomorrow I'll have the opening done in 1280x800 with audio as a proof of concept. That should motivate me to start updating all the graphical assets and fix the 1Ch thread once an for all.

(I made an edit to this blog after the fact. My secure code looked awful!)

Saturday, January 6, 2018

Music Man

Yea, I'm working on my day off, but the music is done. On my first attempt to convert the MT-32 MIDI into GM, I accidentally scrubbed the program change commands that made each channel change to a different instrument (Not every channel has just one instrument patch). Now that I had an event editor I manually changed each program change event to select the correct instrument. I then ran into another issue. I couldn't find a single SonfFont that sounded good with all the tracks. Either the orchestra hit was too loud, or just used the strings, or another had the harp slightly out of tune. In the end I selected which SoundFont sounded best for each track and exported all the tracks individually as a wave file. Then I imported all the tracks into Audacity and balanced each track to make it sound the best. After that, one big export into MP3 and the music conversion is complete. On Monday I'm be back to coding, starting with redefining the config file to allow for different resolutions, mouse settings, and volume controls.

Here's a snippet of the final music.


Friday, January 5, 2018

Competing Standards

Left General Midi, Right Roland MT32
Remember when I said that I couldn't recall if it was Roland or Yamaha who had the non-standard MIDI mapping. Turns out it was both. Call me old fashioned, but when I learned MIDI back in the day, it was with a Korg X1 and an Apple II running my sequencer. (Okay, I'm dating myself now). I just used straight, standard General MIDI. I never had to deal with the strange MIDI dialects from the 90s.  The original ROE title was composed with a Roland MT-32 in mind, and that does not adhere to the General MIDI for the most part. That's why it sounded so awful when I tried to play the title music "out of the box". There are all kind of strange weirdness for that MIDI device. First you can only have 9 tracks, not 16. These are numbered 1-8 and then R for the rhythm. These map to general MIDI track 2-9 and 10 for percussion. Also, the instrument patches are not the same. I created a spreadsheet to see to see what maps to what.

Even though Yamaha really isn't in this picture, that company's changes were a little more standard and some of the extensions made sense. For example, you could have more that 128 sounds, but made it so the percussion track wasn't hard-coded to the 10th track. You had to map a drum kit instrument to the track instead.

I contemplated just rendering the music though an MT-32 emulator. Sadly, the sound samples are copyrighted by Roland and they have been known to get litigious in the past about using their samples in an emulator. It appears I will need to slightly resequence the title music to have it conform to General Midi. This includes patching the instruments back, which I have done, but I also need to remap the controllers (Volume, Pan, Sustain) and scrub the proprietary Roland SysEx (System Executive) events. This is why my volumes, sustains, and pans were all over the place.

The good news is I have a better sequence editor. The other one I had was pretty basic and just gave me the ability to edit the piano scroll and some tracking elements. The one I have now has a track editor, piano scroll editor, notation, and the ability to manually edit the event timeline. It's the event editor that is the most useful. It's also the oldest of old-school ways of editing MIDI. Back in the day, the event list was all I had on the Apple II.

I'll be playing catch up the weekend and hopefully have a nice sounding title theme when I'm done.



Thursday, January 4, 2018

Wearing hats

Getting Over It
What makes this whole ROE port interesting is that there is not a shortage of things to do. One of my bad habits is that I can tend to obsess about something and then do that thing until I burn out. After I was able to get the original ROE code to compile and limp along, the holidays hit. After that, I felt almost like the guy in the pot from "Getting Over It with Bennett Foddy". I'm going to have to crawl back up the mountain, this time in high resolution. Along the way pick up the detritus of code I've left behind just to get the system to function. This time it'll be in glorious 1280x800. As of right now, I'm not too keen on going back into Visual Studio, and following my call maps from Doxegen just yet.

This game does have me wearing different hats all the time. I can code, and was a database programmer one upon a time many moons ago. I'm rusty and flail sometimes, but can get things to work with effort. I'm not sure of that's how programmers are, but I've been told that is most often the norm. I have met with programmers who literally plug in headphones and zone for 16 straight hours. I've been in that zen in the past once or twice, but my brain doesn't make a habit of it.

I can also draw, and in my inventory have both a Wacom tablet and scanner. I'm okay  with GIMP and can do some of the more advanced mechanical stuff. That being said, never used Photoshop. I'm also pretty average in Inkscape, and once again, never used Adobe Illustrator. I can model 3D models, animate, and do video editing in Blender, but never touched 3D Studio Max. It seems I'm just one step short of "Pro", but It's a comfort zone I guess.

Arrows show the wrong patching
So today I decided to wear yet another hat and fix ROE's music.  The first thing I did was convert the MIDI file into sheet music so I could see what I was looking at. That way I could break down the movements and figure out what was channeled to what. The sequencer I have is a bit clunky and I wasn't getting the info I needed by looking at the piano scroll.

On import, I immediately found out what the problem was. It was channeled all wrong. I have a screenshot here showing that what each track was being labeled as, and what channel it was using was way off. I'm not sure why it was like this, but I fixed it up.

A little MIDI 101:

MIDI files are basically digital piano scrolls. They simply tell an instrument when and how to hit a note and for how long. They don't have any audio in them though. Instruments can be physical musical keyboards, drum machines, or digital synthesizers. Nowadays MIDI is also used for controlling stage lights and things like that due to their event-like system. MIDI has "tracks" that you put notes on and maps to one of 16 "channels" where you can, by convention, select one of 128 different instruments or sounds. The issue with ROE's title music was the tracks were not mapped to the proper instrument. (You can also change instruments on the fly in a track using an event, but that's me getting ahead of myself)

The default playback instrument is what you have plugged into the MIDI system. Back in the day, the Adlib and Soundblaster sound cards emulated the 128 interments as best they could with the OPL2 chips they had. Nowadays, Windows (Well, DirectX to be more specific ) comes with a digital  wave table synthesizer by Microsoft that uses digital samples for instruments. It sounds... well, fairly bland. You can "plug in" your own synthesizer, which is what I've done, and use SoundFonts to get better samples.

Soundfonts are kind of a lost art now. In fact, many of them are found online packed in a format that you decompress with a program that's not made anymore. By luck I found it, but wow. Talk about locking your keys in the car!

Right now I'm trying to find the best SoundFont to render the music with. I may have to make my own as each sound a little strange for a particular channel. After that I will finally dive back into Visual Studio and re-do the title sequence in high resolution with proper music and everything.

Here is a sample of before (OPL2) and after (Wavetable) when it comes to the title music It's not done yet, but sounds much better :)


Wednesday, January 3, 2018

Low Key

My work ethic was in the toilet today. Getting back into working after the holiday is kind of a drag. I finished up the HD graphic assets for the title sequence, and poked around at the MIDI opening music. It's constructed really weird. It seems that the better the quality SoundFonts I throw at it, the worse it sounds. I know it sounds "fine" with the Yamahama YM3812 synth. (As fine as it can get anyway). The Game was designed for Roland MT32, so I may have to go down the MIDI rabbit hole and see if the tracks are are not channeled correctly. I can't remember if it's Yamaha or Roland that "broke" the General Midi rules about percussion channel placement. It's supposed to be channel 10, but one of those two did an extension and moved the drums around. I mention this because while playing the opening, I'm hearing what is supposed to be timpani drums are coming out as tubular bells. There is also the most obnoxious "whoosh" sound coming from the score at random times. I'm wondering if that's not supposed to be the credits coming in and out, or did a track get stuck on "applause". I'll peek into this tomorrow.

On the flip side I figured out how to override the Microsoft GS Wavetable Synth with a software synthesizer that supports SondFonts. This means I can edit the MIDI sequence and play it back in my editor with the correct sounding instruments . After I'm done I'll be able to render it to MP3 with Fluidsynth and the same SoundFont.

Looks better then the CGA version

Tuesday, January 2, 2018

Powers of 10

In 1977 there was a popular science film from IBM called "Powers of 10". It started with a view of 1 meter square and scaled up to the observable universe. Then the film took us back down to 1 meter, and started zooming into the microscopic world until we arrived inside a proton. You can click the link to go to the video on YouTube. What's interesting is how much science had progressed since the film was made. To give an idea of how far we have come, the move signposted 1024 meters (100 million light years) as the edge of the observable universe. Nowadays we can see to the Cosmic Microwave Background radiation, which was mapped with NASA's COBE satellite in 1989. The CMB is about 46 billion light years away which is 4.4x1026 meters. As the universe is expanding, the furthest we will ever be able to see is 65 Billion light years, which is 5.9x1026. (We actually can't see that far because the CMB is in the way, and the universe was opaque before that time). As the universe expands, that number is going down. (Every day we see less and less of the observable universe because it's expanding faster than light)

In the other direction, the video goes to 10-15 meters. The smallest detectable thing we have now is the width of a 1 MeV neutrino which is 2 × 10-23 meters. This was detected with the Large Hadron Collider. However, the smallest thing that can be is plank length, which is 1.62×10-35 meters. This is currently being measured with the help of a watt balance to define a kilogram.

The point of this whole story is that I'm now working on the high resolution assets for ROE. One of the things I did was correct a few dates. Science progressed a bit since 1991. In a previous post I mentioned the opening titles said that the universe was 16 billion years old. It's actually closer to 13.82 billion. The credits also said that man emerged 4 million years ago. Last year a scientific paper came out that showed humans split from the Least Common Ancestor of chimps 12 million years ago. The split took a particularly long time to complete because there was a lot of genetic transfer during that time. Anyways, I corrected that date too.

I'm pretty happy with how the updated graphics are looking. I do have some plans for the humans and aliens in the game and how they are going to look. I'm trying to keep the look and feel as close to the original game as I can, but those human designs are going to get a much needed overhaul. (While keeping the same uniforms)

The opening music will be an MP3 rendering of the original MIDI. Digital version I have right now was played on an emulated Yamaha YM3812 chip that comes on a SoundBlaster. I tried to re-render the MIDI it using FluidSynth and an orchestra Soundfont. The output was pretty much a disaster, but the parts that were good were awesome. I'm probably going to re-sequence the original MIDI so it will render better. The events are fine, but I'll need to re-channel the tracks to better match the patches in the Soundfont.

Happy New Year!