For some time I've been looking at making a MIDI synthesizer in AS3 (Adobe Flash). Since AS3 doesn't natively support playing MIDI files (or reading them for that matter) this is a bit of a challenge. Through research I've learned of some methods that allow a binary file to be embedded and loaded as a byte array. From that point it's whatever handy work you can muster to interpret a byte array.
Has anyone worked with the MIDI file format or know of a good starting point for me to roll a MIDI interpreter? I understand the file structure a bit and I've read a little about generating different tones and sounds with saw waves, sine waves, square waves, triangle waves, et al, but I'm looking to accomplish this in AS3. I saw the tutorial here on OGA (opengameart.org/forumtopic/kickin-it-old-school-setting-up-nes-style-chiptunes) and read that too by the way.
There's a project that can play a MIDI file from Flash Player called SiON (wonderfl.net/c/4IH3). I've looked at that but haven't tried to implement it. I don't know if the sound quality it produces is good enough or it'll just annoy players. Particularly, it makes violins sound like synthetic pipe-organs and murders a few grand piano sounds without regard. It hits the right key and pitch but sometimes that's about all it can do.
Due to technical constraints, I'm forced to make an AS3 based game of less than 10MB total finished SWF size, only a single SWF, and it can't make remote calls for resources. So far the graphics I've chosen and had fabricated (by Sharm and the other awesome artists here on OGA) are well under that 10MB cap once compiled. I'm still struggling with the sound portion (pretty important component of any finished game). Since using 2-3 good MP3 files eats most of my size restriction I have to go with an ultri slim file type like MIDI.
Please OGA community, in your vast and collective wisdoms and interweb crawling mastery, how do you think I should proceed with making a MIDI music player for my Flash game?
AS3 is a bit out of my area of expertise, since I've never worked with it, but here's how I would go about it:
First off, apparently there's an alpha quality midi loader on google code under the MIT license:
http://code.google.com/p/as3midilib/
Grab the code to that.
Then, write a few simple synths (white noise, square, triangle, saw, etc) and associate them with whatever midi channels you want (obviously you're not going to want to write synths for every single standard midi instrument, because that would take forever).
I've never written a music synth before, but I'd try something like this:
That's about it. If you need anything clarified, let me know.
Bart
There is a mod player for Flash that works fairly well, but there is not a MIDI player for Flash at all, at least not one that actually works out-of-box. You will need to make synths and all that jazz. I have used the mod player inside of Flixel as a replacement library for music to keep the filesize low, and the CPU hit is minimal.
Syrsly
Twitch Streamer, Web/Game Developer, & Artist
syrsly.com - contact me for commissions, thanks!