Making the ultimate Sega Genesis sound driver
Posted: Thu Jun 21, 2012 9:53 am
The title of the topic is kinda exaggerated but the idea is there 
SGDK contains some Z80 sound drivers but none of them can be really used as a "in game" sound drivers... PCM drivers support PCM only (without FM nor PSG) which made them not really suited and TFM as MVS does not support easy SFX playing.
What i want to do is to make a new driver supporting both play music as play SFX commands, also i want to provide more than the usual 6 FM + 4 PSG or 5 FM + 1 PCM + 4 PSG.
For instance i think it is very possible to do 5 FM + 4 PCM + 4 PSG.
For that PCM would be fixed at 8 bits @16 Khz and 256 bytes aligned for instance. Also the Z80 would only handle FM registers and PSG registers writes without any complex format decoding.
I believe VGM is already working this way (only give writes command for FM and PSG + PCM stuff) it's why i would like to stay on this "standard" format. I think VGM can actually support that type of driver (i.e. 5 FM + 4 PCM + 4 PSG) as you can specify severals PCM sources and formats but Shiru or Delek are better placed than me to reply that question.
So initially the idea of this topic is to discuss about what could be the ultimate Sega Genesis sound driver to gives the system the best music we could have then try to implement it
- The driver has to run entirely on Z80, the 68k CPU pass basic command as "play/stop music" or "play sfx on channel x".
- The driver should permit usage of 6 FM / 5 FM + DAC and 4 PSG.
For me the big of the discussion is about PCM handling.
Shiru wrote sometime ago a 4 PCM player driver (6 bits @ 16 Khz).
Samples has to be 256 bytes boundary but the driver was using about 50% of CPU time, leaving enough slot to handle FM and PSG.
Inspired by his code (which mainly use buffering) i wrote a lot of others Z80 drivers :
4 PCM 8 bits @16 Khz
4 PCM 8 bits @16 Khz with envelop support
2 DPCM 4 bits @22 Khz ...
1 PCM 8 bits @8/11/16/22/32 Khz
...
Given all that possibilities i wonder what could be the best format for general music creation on Sega Genesis.
I think the more PCM channels we have, the best it is... but the more PCM channels we have, lower the playback rate is.
For instance we can do :
- FM + PSG + 8 PCM@8/12 Khz
- FM + PSG + 6 PCM@12/16 Khz
- FM + PSG + 4 PCM@16/20 Khz
- FM + PSG + 3 PCM@22 Khz
...
The second playback rate is the "optimist" one (with a good driver).
Also we can though about 4 bit ADPCM but then we reduce the number of channels to gain ROM space :
- FM + PSG + 4 ADPCM@8/11 Khz
- FM + PSG + 2 ADPCM@16/20 Khz
How do you the see the ideal format ? Discussion is open
Shiru : FM + PSG + 2PCM 7 bits @variable rate (up to 23 Khz)
Stef : FM + PSG + 4PCM 8 bits @16 Khz

SGDK contains some Z80 sound drivers but none of them can be really used as a "in game" sound drivers... PCM drivers support PCM only (without FM nor PSG) which made them not really suited and TFM as MVS does not support easy SFX playing.
What i want to do is to make a new driver supporting both play music as play SFX commands, also i want to provide more than the usual 6 FM + 4 PSG or 5 FM + 1 PCM + 4 PSG.
For instance i think it is very possible to do 5 FM + 4 PCM + 4 PSG.
For that PCM would be fixed at 8 bits @16 Khz and 256 bytes aligned for instance. Also the Z80 would only handle FM registers and PSG registers writes without any complex format decoding.
I believe VGM is already working this way (only give writes command for FM and PSG + PCM stuff) it's why i would like to stay on this "standard" format. I think VGM can actually support that type of driver (i.e. 5 FM + 4 PCM + 4 PSG) as you can specify severals PCM sources and formats but Shiru or Delek are better placed than me to reply that question.
So initially the idea of this topic is to discuss about what could be the ultimate Sega Genesis sound driver to gives the system the best music we could have then try to implement it

- The driver has to run entirely on Z80, the 68k CPU pass basic command as "play/stop music" or "play sfx on channel x".
- The driver should permit usage of 6 FM / 5 FM + DAC and 4 PSG.
For me the big of the discussion is about PCM handling.
Shiru wrote sometime ago a 4 PCM player driver (6 bits @ 16 Khz).
Samples has to be 256 bytes boundary but the driver was using about 50% of CPU time, leaving enough slot to handle FM and PSG.
Inspired by his code (which mainly use buffering) i wrote a lot of others Z80 drivers :
4 PCM 8 bits @16 Khz
4 PCM 8 bits @16 Khz with envelop support
2 DPCM 4 bits @22 Khz ...
1 PCM 8 bits @8/11/16/22/32 Khz
...
Given all that possibilities i wonder what could be the best format for general music creation on Sega Genesis.
I think the more PCM channels we have, the best it is... but the more PCM channels we have, lower the playback rate is.
For instance we can do :
- FM + PSG + 8 PCM@8/12 Khz
- FM + PSG + 6 PCM@12/16 Khz
- FM + PSG + 4 PCM@16/20 Khz
- FM + PSG + 3 PCM@22 Khz
...
The second playback rate is the "optimist" one (with a good driver).
Also we can though about 4 bit ADPCM but then we reduce the number of channels to gain ROM space :
- FM + PSG + 4 ADPCM@8/11 Khz
- FM + PSG + 2 ADPCM@16/20 Khz
How do you the see the ideal format ? Discussion is open

Shiru : FM + PSG + 2PCM 7 bits @variable rate (up to 23 Khz)
Stef : FM + PSG + 4PCM 8 bits @16 Khz