Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by RetroGames » Mon Jan 25, 2016 8:26 am

Not only am I a Gendev noob, I'm a sound and music noob also. (And a graphics, animation, programming, and maths noob, but that's beside the point. 8) ) But noob or not, sound matters a lot to me. It's really the main reason why I decided to learn Gen/MD programming: access to an awesome synthesizer inside an awesome game console at no extra charge. :D

Well anyway, I came across this thread where I found something that got me very curious:
Stef wrote:With SGDK you have different possibilities to have music & SFX in your game :
- Echo sound driver
- VGM sound driver
- XGM sound driver
- 2/4 PCM channels sound driver.

I recommend you the XGM sound driver as it's able to play .VGM file (as the VGM driver) while allowing 4 PCM channels (you can reserve 3 of them for SFX).
Specifically, I was surprised to read that you can get 4 PCM channels out of the Genny. I thought that was impossible with ordinary hardware, because I know the console only has 1 channel capable of playing samples, which is what I thought PCM was all about. Then I remembered that I don't know anything about how audio works. :oops:

So the question is: Is it possible to get simultaneous / polyphonic playback of two or more samples out of the Genesis using only YM2612 + PSG, with no add-ons (such as the Sega CD)? If so, would someone be so kind as to explain how this works? If you know of any games or demos that actually demonstrate this use of simultaneous samples, that'd be awesome too!
Last edited by RetroGames on Fri Feb 05, 2016 4:56 am, edited 1 time in total.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by Stef » Mon Jan 25, 2016 9:36 am

Actually the Sega Genesis hardware indeed offers a single PCM channel through FM channel 6 (YM2612) but you have the Z80 CPU dedicated for sound so you can somewhat do software PCM channels mixing to have more than 1 PCM channel. That is exactly what the XGM driver does, it spent about 70% of the Z80 time in doing 4 PCM mixing stuff and keep the other 30% (which is enough) to handle all others YM, PSG and externals commands.
So you can have 4 PCM channels playing at same time on Sega Genesis, but unlike the Sega CD PCM chips, you cannot change the pitch nor volume... all PCM play at a fixed playback rate (14 Khz with the XGM driver) and fixed volume.
There is another full PCM driver in SGDK (no YM or PSG stuff) which allow you to play 4 PCM at 16 Khz with 16 volume levels but still no pitch adjustment.

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by RetroGames » Mon Jan 25, 2016 3:27 pm

Stef wrote:Actually the Sega Genesis hardware indeed offers a single PCM channel through FM channel 6 (YM2612) but you have the Z80 CPU dedicated for sound so you can somewhat do software PCM channels mixing to have more than 1 PCM channel. That is exactly what the XGM driver does, it spent about 70% of the Z80 time in doing 4 PCM mixing stuff and keep the other 30% (which is enough) to handle all others YM, PSG and externals commands.
Let me see if I understand this... Is what you're describing similar to how older single core, single CPU computers can appear to be multitasking, even though they technically can't multitask at all? In other words, are we just switching tasks so quickly that it appears we're getting polyphonic samples, when really we're not ("software PCM," as you put it)?
Stef wrote:So you can have 4 PCM channels playing at same time on Sega Genesis, but unlike the Sega CD PCM chips, you cannot change the pitch nor volume... all PCM play at a fixed playback rate (14 Khz with the XGM driver) and fixed volume.
There is another full PCM driver in SGDK (no YM or PSG stuff) which allow you to play 4 PCM at 16 Khz with 16 volume levels but still no pitch adjustment.
Are these pitch and volume restrictions imposed by the drivers you mentioned, or are they hardware limitations (in the case of PCM only - I know the volume and pitch of FM and PSG channels can be changed)? And by the way, is it possible to get more than 4 PCM channels, or is something preventing that?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by Stef » Mon Jan 25, 2016 4:31 pm

RetroGames wrote: Let me see if I understand this... Is what you're describing similar to how older single core, single CPU computers can appear to be multitasking, even though they technically can't multitask at all? In other words, are we just switching tasks so quickly that it appears we're getting polyphonic samples, when really we're not ("software PCM," as you put it)?
Well not really :p Software mixing is done by using buffering... So you read out a portion of PCM#1, store it inside a buffer, read a portion of PCM#2 then mix it with PCM#1.. and so on until you're done with all four PCM samples. Then you take the mixed result and sent it to FM6. Still that require sort of "multitasking" in the sense you need to continuously feed the DAC register (FM 6) to play sample on Sega Megadrive. So you need to write your driver cleverly to be able to feed the DAC while doing others tasks, hopefully you have the whole Z80 dedicated for that.
Are these pitch and volume restrictions imposed by the drivers you mentioned, or are they hardware limitations (in the case of PCM only - I know the volume and pitch of FM and PSG channels can be changed)? And by the way, is it possible to get more than 4 PCM channels, or is something preventing that?
The hardware do not provide anything about it, it's just a DAC so everything has to be done through software... and a ~4Mhz Z80 limit you in what you can do with software sound processing of course. You can eventually have more than 4 PCM channels but then you will have to lower the output rate i guess. If i'm able to get 4 PCM @16 Khz for instance, you can consider than 8 PCM channel would require to lower output rate @8Khz.

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by RetroGames » Tue Jan 26, 2016 8:47 am

Stef wrote:Software mixing is done by using buffering... So you read out a portion of PCM#1, store it inside a buffer, read a portion of PCM#2 then mix it with PCM#1.. and so on until you're done with all four PCM samples. Then you take the mixed result and sent it to FM6.
OK, so we're not "multitasking" / rapidly switching between 4 samples, we're mixing (summing?) 4 samples together "in software" and then playing the mixed signal over the one hardware DAC channel, FM6?
Stef wrote:Still that require sort of "multitasking" in the sense you need to continuously feed the DAC register (FM 6) to play sample on Sega Megadrive. So you need to write your driver cleverly to be able to feed the DAC while doing others tasks, hopefully you have the whole Z80 dedicated for that.
This I definitely don't understand. What does "continuous feeding" mean? Do the other non-DAC channels (FM or PSG) not need to be continuously fed?
Stef wrote:You can eventually have more than 4 PCM channels but then you will have to lower the output rate i guess. If i'm able to get 4 PCM @16 Khz for instance, you can consider than 8 PCM channel would require to lower output rate @8Khz.
This sounds like it makes sense, but I know I need to know more to really understand what you're saying here. Rather than me asking a bunch of basic questions, could you tell me instead what specific subjects I should look into to understand how audio works? I think I need to begin at the beginning, but I'm not quite sure where the beginning is at this point! :oops:

EDIT: That last paragraph I wrote sounds a little whiny. Sorry about that. I was tired and a little frustrated when I wrote it. I think I just need to clear my head and try to do more research later. If you happen to know any good "intro to audio" guides to point me at, that's awesome, but at the end of the day, I know I won't get far if all I ever do is ask "Where do I start?" instead of jumping in and doing my part in the learning process. And hey, thanks for all the great info you've already given me!

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by Sik » Wed Jan 27, 2016 9:05 am

RetroGames wrote:OK, so we're not "multitasking" / rapidly switching between 4 samples, we're mixing (summing?) 4 samples together "in software" and then playing the mixed signal over the one hardware DAC channel, FM6?
Yep.

And heck, when hardware supports multiple channels, it's literally doing exactly that as well. It's just that in this case you have a program doing it with the Z80 instead, although of course that means it has little time to do anything else then. But yes, it's just "grab one sample from each 'channel', add them and send it to the hardware".
Sik is pronounced as "seek", not as "sick".

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: Noob questions: is playback of multiple, simultaneous samples (samples polyphony) possible on the Genesis?

Post by RetroGames » Wed Jan 27, 2016 10:28 am

Sik wrote:
RetroGames wrote:OK, so we're not "multitasking" / rapidly switching between 4 samples, we're mixing (summing?) 4 samples together "in software" and then playing the mixed signal over the one hardware DAC channel, FM6?
Yep.

And heck, when hardware supports multiple channels, it's literally doing exactly that as well.
Cool, thanks for the clarification and additional info. :D

Post Reply