This is a program that converts MIDI files and outputs the converted music in one of three formats for the CoCo to playback. It outputs the music data alone or along with the player for the given format. The output formats that are supported are:
- Simon Jonasson’s – DIPOLE.ASM software music player
- John Linville’s – Game Master Cartridge support with my software player
- Ed Snider’s – CoCo Programable Sound Generator with my software player
The program started out as a simple command line based tool that would take MIDI (.mid) files and output them in a format that would playback on Simon’s dipole.asm software music player. I had the basic MIDI converter working where it would just describe the instrument and ask you what two instruments you wanted to convert. This really meant that in order to use the tool you would have to prepare your own MIDI file removing tracks you don’t want, (which might still be necessary for complicated songs.) This would be OK for a quick and dirty converter but I figured if I’m going to share this with others that I should make it a little more user friendly.
I then decided that I would show the user all the tracks and let them pick the instruments from a GUI. This really works well since it shows you what instruments are used for the different parts of the song. If any one instrument is used for only part of the song then you could see it and actually select a few instruments as long as they didn’t play notes at the same time. You couldn’t figure this out without looking at the song with the separate track all laid out on the screen.
Once I got the GUI working and was able to convert the MIDI files to Simon’s Dipole.asm format I realized I could do a similar thing for John Linville’s Game Master Cartridge. Since MAME supports the cartridge it allowed me to experiment and learn how to program the Texas Instruments SN76489 sound chip that is used inside John’s cartridges. I was just about finished working on my own GMC format player when Ed Snider posted on Facebook that he was ready to send out some CoCo Programmable Sound Generator cartridges. So I bought one off Ed and continued to finish up the GMC format and add in my MIDI to GMC format player code. Since Ed’s cartridge is more of a dedicated sound card for the CoCo that would stay in your Mult-Pak Interface I figure it would be helpful to BASIC programmers if I made my MIDI 2 CoCo converter output the music and player in a way that anyone could easily use it to add background music in their programs.
Here is what the MIDI to CoCo converter can do, it converts MIDI files to:
- Simon’s dipole player format along with the player all ready to have an assembly programmer add their code to the end of the program and it will automatically include the music in the background.
- Simon’s dipole player format, just the music data in assembly FCB format which you can add to your own assembly program and add Simon’s dipole.asm music playing code in your own program.
- John Linville’s GMC playable format along with my own player in a format that can be used in creating your own game cartridge to easily add music to your game. ready to be tested using MAME
- John Linville’s GMC compatible format assembly FCB format file to be used with my GMCPLAY.asm program to be used in your own game cartridge code
- Ed Snider’s CoCo PSG playable format with my own player that can be easily added as background music to your BASIC program. The sound data is stored on Ed’s CoCo PSG 512k RAM leaving lots of room for your BASIC program.
- Ed Snider’s CoCo PSG playable format with my stand alone PSGPLAYER.asm that can be used as part of your own assembly program/game and easily allow you to add background music to your assembly program.
Where do I download the program?
Need to Install QB64 on your modern computer
The converter is written in QB64 which is BASIC for modern PC’s. You can use it on Mac, Linux and Windows. It takes your BASIC program and in the background turns it into C++ code which is then compiled on the host computer and outputs a completely independent program that is ready to be executed on that host computer. It doesn’t need any other support files or libraries it is ready to be executed as it is and since it is run on a modern computer it runs super fast! First thing you need to do is install QB64 on your modern computer.
Once installed you take my basic program (mid2coco.bas) and load it into QB64. Then you click on Run | Save EXE in the source folder. Finally click on Run | Make Executable Only. From that point on you have a stand alone program that can be moved and used just as any other program on your computer.
Make sure the mid2coco executable file is in the mid2coco folder. If you want to use the mid2coco program in a new folder you need to have the mid2coco program along with the following files that are required for certain output modes. You need to have GMC_Play.asm, Dipole_Part1.asm and Dipole_Part2.asm along with the MIDI files that you want to convert in that new folder. You run the program from the command line. Change your directory so you are in the directory with the new mid2coco executable that you just made and use this command:
For example to convert a MIDI file called Axelf.mid:
Then the program asks you what output format you would like. Select the output based on the output format you require as per the picture below:
Select the output format you want (1 to 6). Also you can add the letter p after the number to have the program output the music data for the proper playback speed for PAL computers (for example 5p) otherwise it will default to using NTSC timing. Note the PAL timing hasn’t been tested.
Next you are asked if you want to transpose the MIDI file one octave higher, since some older MIDI files were created this way. Most of the time you can just hit enter as the default is No.
Next it asks you what type of CoCo you will be using the program on. This really doesn’t matter except if you are using Ed Snider’s CoCo PSG from BASIC where it will give you some instructions of using the loader and player in BASIC, and what the addresses are to start, stop and continue playback.
Next you are shown a list of the tracks and the instrument names for each track that is in the MIDI file.
If you selected Simon’s dipole.asm format then you can only choose two voices. If you choose John Linville’s GMC format you can choose three voices for tones and the fourth only for the drum track. If you selected Ed Snider’s CoCo PSG then you can choose from three voices for tones or use voice three as a drum track. If you want to use voice 3 for drums then make sure click on the boxes with the number 4 and no boxes with the number 3.
Since we are limited to individual notes per voice there is one other thing to note about track selection. During the MIDI conversion of chords the program always selects the highest note of the chord as the note to convert unless you select more then one voice for the same track. The program works like this… If you want to play notes of a chord from your MIDI file select voice 1 and 2 for the same track. The program will then use voice 1 as the high note of the chord and voice 2 as the lowest note in the chord. If you select voice 3 in the same track with voice 1 and voice 2 then voice 3 will play the 2nd highest note.
As for picking which tracks are played by which instrument you use the mouse and left click on the little box with the number of the voice you want to use for that track. Use a right click to cancel the voice selection. There are many songs that have many instruments but not all of the instruments are playing all the time. For example the picture below is the GUI output for the file Axelf.mid using Simon’s dipole format which only allows you to choose two voices.
You can see that only tracks 1 and tracks 2 are used throughout the entire song. So you could select voice 1 for track 2 (slap Bass 2) and you can select voice 2 for track 3, track 4, track 5 and track 7 since none of these tracks play notes at the same time. The instruments will all sound the same but at least you will get more of the original notes that are in the song and it’s usually good enough for background music for your game.
See the picture below with the little coloured boxes that indicated which voice I’ve selected for each track. Sometimes the MIDI converter is unsure if a track is a drum track or not and will display “??? Instrument or Drums” it doesn’t display a box with the number 4 beside it but if you place your mouse pointer to where the box would be you can click on the imaginary box and it will turn white to indicate that the converter will use this voice as drums using the selected track.
Once you’v selected your tracks, then press the Space Bar or Enter to start the conversion of the tracks and voices you’ve selected.
You will then be shown a little summary screen of what the program did during the conversion and will tell you a little bit more about the song. It will tell you the length of the song and the size of the data that is needed to play the song. It will also give you some information on how you can use the output format that you’ve selected. Press any key at this point to close the mid2coco program. Then you will either have to use the output in your own assembly program or if you are using Ed Snider’s CoCo PSG you can use it from BASIC, or in your own assembly language programs. I’m not going to go into details here for using each format. But if you play with the program and look at the output files it produces I’m sure you will understand how to use them for your own projects.
CoCo PSG background music from BASIC
If you have Ed Snider’s CoCo PSG you can use option 5 to convert the MIDI file so it will play in the background of your BASIC program. Then follow the instructions as described above to convert the MIDI file to a file called PSGLOADR.BIN. All that is needed is to copy the file generated called “PSGLOADR.BIN” to the floppy disk or .dsk image if using CoCoSDC. The PSGLOADR.BIN is a loader program that will copy the music data which is also in the PSGLOADR.BIN file and copy it to the RAM of the CoCo PSG. So your music data won’t take any RAM from your CoCo. The PSGPLY16.BIN or PSGPLY32.BIN programs which are the actual playback programs will require about 1150 bytes of RAM from BASIC and these programs need to be on your disk. You actually need only the one program depending on the amount of RAM in your CoCo. If you have 16k then you only need the PSGPLY16.BIN program on the floppy disk. If you have 32k or more, even a CoCo 3 then you need to make sure the PSGPLY32.BIN program is on the floppy. The last thing you need to do is add a few lines of BASIC code to your BASIC program. The converter will let you know what these lines of BASIC code are depending on the amount of RAM the CoCo target system has. The converter will also let you know the EXEC commands to start, stop and continue the music playback in your BASIC program. The last thing it will let you know is the POKE address you use to set the number of times the music will repeat (default is continue looping forever). All the programs required are included in the .dsk image and as stand alone files in the mid2coco.zip package.
Take a look at the program listing for the included programs PSGPLY16.BAS or PSGPLY32.BAS to see how to load and start the music. It also shows the EXEC addresses to stop and continue playback.
Some other things to note about the conversion and using the music in your own programs. The mid2coco converter takes velocity into account but Simon’s player always plays notes at the same volume level. The other two formats support velocity and the program does output the notes and their volume level according to the info in the MIDI file.
Also note – Since the GMC and CoCo PSG are cartridges that produce sound the mixer inside the CoCo must be set to output sound from the cartridge port to the speaker on your TV. Once the mixer is set as the cartridge as it’s input you can no longer use the CoCo DAC for sound effects. You will have to use the sound chip on the cartridge for sound effects in your game. Or temporarily turn off the cartridge mixer and select the CoCo DAC then switch back to the cartridge to play the music again. If you are using the CoCo PSG from BASIC with my converted player and you get an error then the CoCo will set the audio mixer to the internal DAC even though the music will still be playing in the background and you wont hear it. The easiest way to get the sound set back to the CoCo PSG is to EXECute the stop command then EXECute the Continue command (shown in the example PSGPLY16.BAS or PSGPLY32.BAS files). Also note if you EXECute the start address twice it will crash the CoCo since the start EXEC actually sets up to intercept the BASIC IRQ routine and if you do it a second time it will intercept it’s own routine and that is bad.
Also a note about the GMC playback routine, the assembly code copies the playback routine from the cartridge to RAM at address $7000 as a default. If you are going to use this code with a real game cartridge you should probably change this address to something that makes more sense for your program.
If you want to get a Game Master Cartridge reach out to John Linville here
If you want to get a CoCo PSG visit Ed Snider’s webpage here
CoCo PSG player format description
* 5 Byte header: * Byte Value * 00-02 'PSG' - Header Identifier * 03 $xx - File version # currently only supports a value of $01 for version 1.00 * 04 $xx - Number of times to loop this song where xx is: * $00 - Don't change the number of loops value * $01 to $FE - loop this number of times * $FF - loop forever * All bytes at this point are data bytes that are encoded as per the info below. * * First the descriptor byte * Left nibble = # of vsyncs/2 to count until next change in tone or velocity is done * $0x to $Fx = 0 to 15 delay count before next note or velocity change, add one to get real value of 1 to 16 * * Right nibble = # of bytes to copy (1-11) count of bytes to copy max needed in current format is 3x3 = 9 bytes = (2 tone values, 1 velocity value for each of the 3 voices) * or if the value of the right nibble is higher then 11 or $0B then do the following * $x0 = 00 unused * $xC = 12 signals the repeat count is larger then 16 so use the next byte as the repeat count (left nibble = bytes to copy) * $xD = 13 signals the repeat count is larger then 256 so use the next 2 bytes as the repeat count (left nibble = bytes to copy) * $xE = 14 Flip Channel C from tones to noise or drum track or back to tones * $xF = 15 signals End of Music data * * Next process the data bytes * * My PSG playback format uses the following format for the data bytes * * ,------------- 0=Note, 1=Volume or channel C Noise/Drum frequency * | ,,----- Channel 00=chan A, 01=chan B, 10=chan C, 11=chan C - Drum/Noise info * | || * |Xxx xx|| x=volume or msb of 12 bit tone info or Xxxxx = 5 bit noise/drum frequency for channel C * 1000 0001 * If it is a Note then it has the 4 msb of the 12 bit tone and the next byte has the 8 lsb's of the 12 bit tone value (so two bytes are always needed for tone data) * Done, the next byte is the next encoded byte...
Game Master Cartridge Format Description
There is no header to the data stream since it will be played back from the cartridge directly. The encoding for the music data is:
* Encoding byte * left nibble = # of times to repeat 0 to 15 repeat count * * right nibble = # of bytes to copy (1-11) count of bytes to copy * 12 signals the repeat count is larger then 15 so use the next byte as the repeat count (left nibble = bytes to copy) * 13 signals the repeat count is larger then 255 so use the next 2 bytes as the repeat count (left nibble = bytes to copy) * 14 signals jump to the next Bank of the GMC (reached the 16k length of the current bank) (ignore left nibble) * 15 signals End of File