Midi -> VGM Converter - SN76489
---------------------
by Valley Bell, additional SPSG VST related notes by Aly James

This small tool converts standard MIDI files (.mid) to Video Game Music files (.vgm).
The vgms will use the PSG chip (SN76489) and its variants.

Supported MIDI Controllers (MIDI CC#)
--------------------------
ID	GM Name			Special Effect
7	Main Volume		-
9	[undefined]		not for public use (adds a data block with some text in the VGM)
10	Pan			-
11	Expression		-
16	General Purpose #1	select Noise Mode
				0-63 - white noise
				64-127 - periodic noise
17	General Purpose #2	set PSG 3 frequency Noise Mode (Noise Frequency controlled by PSG 3 Frequency)
				0-63 - disable
				64-127 - enable (in this case transpose the notes to -48 semitones, 4 Octaves lower, if you use SPSG)
111	[undefined]		Loop Controller
				0 - Loop Start
				1+ - Loop End

PSG Noise Fixed Frequencies

If Noise channel is not set into PSG 3 frequency Noise Mode, the 3 fixed PSG Noise frequency can toggled like so:
Note C2 = PSG Noise LOW frequency
Note C3 = PSG Noise MID frequency
Note C4 = PSG Noise HIGH frequency
In this case you can use PSG channel 3 normaly.

Related to SPSG VST
----------------------------------------------------
SPSG Pitch envelopes, Arp & Vibrato

To set the PITCHBEND RANGE accordingly to receive SPSG pitch envelopes (vibrato, arp or pitch EG),
Add those MIDI CC commands at the beginning on the track
CC#101 value = 0
CC#100 value = 0
CC#6   value = 48 (set to 48 semitones)

>> Note that if you plan to use natural recorded MIDI pitchbend in conjunction with vibrato, arp or pitch EG you have to divide the pitchbend data by 4 (pitchbend data/4)
before recording the SPSG MIDI OUT pitch envelopes, so as everything will stay in a 48 semitones range.
Divide by 4 is for a -12 +12 recorded pitchbend range.
More generally the math are: divide by number x = 48/pitchbend range.
So for example if your pitchbend range is set to 2 semitones in SPSG it will be 48/2 = 24 so you will have to divide the pitchbend data by 24
You can use Cubase Transformer to divide the pitch bend data.


PSG Types
---------
- simple SN76489: 1x SN76489 with optional GG Stereo (hard pan)
- dual SN76489: like simple SN76489, but 2 of them
- T6W28: The variant used in NeoGeo Pocket. It has a seperated volume control of left and right channel as well as an extra channel for Noise Frequency.

Clocks
------
- SMS: usual NTSC clock as used in consoles such as Sega Master System or MegaDrive
- NGP: clock of NeoGeo Pocket with 3.072 MHz
- Custom: set you own clock in the field below if you use a custom clock in SPSG
- Dynamic: calculates the clock that's neccessary to correctly convert your lowest notes
        You set the high limit of your clock.

Be careful, low notes may not be converted correctly due to the chip's lower frequency limit.

Volume Calculation
------------------
- Standard: tries to get volume levels that match the MIDI one exactly
- Linear: linear calculation (MIDI 127 = PSG 15, MIDI 64 = PSG 8, ...), good for vgm2mid2vgm or SPSG VST

Channels
--------
The following tables show you how which mode converts MIDI channels to PSG channels.

- Chip-Group
 PSG  | MIDI
------+-------------
 1  I | 1, 9
 2  I | 2, 11
 3  I | 3, 12
 N  I | 4, 10
 1 II | 5, 13
 2 II | 6, 14
 3 II | 7, 15
 N II | 8, 16

- Channel-Group
 PSG  | MIDI
------+-------------
 1  I | 1, 3
 2  I | 5, 7
 3  I | 9, 12
 N  I | 10, 15
 1 II | 2, 4
 2 II | 6, 8
 3 II | 11, 13
 N II | 14, 16

- vgm2mid:
 PSG  | MIDI
------+-------------
 1  I | 11
 2  I | 12
 3  I | 13
 N  I | 10, 14
 1 II | 1
 2 II | 2
 3 II | 3
 N II | 4

As you can see the Drum Channel 10 is always converted to the Noise Channel. (doing it different wouldn't make any sense)
If 2 chips are used, 1/II means that MIDI Channel 1 goes to chip 2. Else all channels go one chip.

[There was a Channel-Map Editor editor planned initially, but I effectively abandoned the project since.]


Notes:
- The MIDI should not have more than one note playing on the same channel at the same time except when you use the SPSG MIDI arp.
