MOD/S3M player for the MD

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

Moderator: BigEvilCorporation

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

Post by Stef » Sun Feb 17, 2008 12:40 pm

Yeah by "clipping" i also understand "limiting", no clipping is just "overflowing" and in this case it's very noticable even on a single byte. As Shiru said, limiting a sample is heavy and can't be handle on Z80 if you're already severals channels mix...

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Sun Feb 17, 2008 10:21 pm

Stef wrote:Yeah by "clipping" i also understand "limiting", no clipping is just "overflowing" and in this case it's very noticable even on a single byte. As Shiru said, limiting a sample is heavy and can't be handle on Z80 if you're already severals channels mix...
Yeah, all mixing and limiting would be done on the 68k side. All the z80 would do is stream the final output.

If you can get 6bit resolution out of PWN, then you could pair with a 6bit sample(shifted) on the DAC for a 12bit output.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Sun Feb 17, 2008 11:30 pm

tomaitheous wrote:Yeah, all mixing and limiting would be done on the 68k side. All the z80 would do is stream the final output.
HardWareMan use that way. He is on this forum, maybe it's worth for you to contact with him?

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Tue Feb 19, 2008 10:41 am

Shiru wrote:
tomaitheous wrote:Yeah, all mixing and limiting would be done on the 68k side. All the z80 would do is stream the final output.
HardWareMan use that way. He is on this forum, maybe it's worth for you to contact with him?
Will do :D

I was thinking, if one were to go the route where the z80 just wrote to the YM DAC and 68k code avoided VDP 68k DMA, Chilly Willy's mention of interleaving two channels would probably be the best way to go. Interleaving the lower and upper 8bits of a 16bit sample at twice the rate (32khz) to the YM DAC for ~16khz 16bit stream seems pretty reasonable for the z80. Skip that whole PWM step.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Feb 19, 2008 8:28 pm

tomaitheous wrote: I was thinking, if one were to go the route where the z80 just wrote to the YM DAC and 68k code avoided VDP 68k DMA, Chilly Willy's mention of interleaving two channels would probably be the best way to go. Interleaving the lower and upper 8bits of a 16bit sample at twice the rate (32khz) to the YM DAC for ~16khz 16bit stream seems pretty reasonable for the z80. Skip that whole PWM step.
That would make a 9 bit sample, not a 16 bit sample. Interleaving ADDS the samples. Two 8 bit samples added together gives a 9 bit sample. You would need a method of multiplying the samples to make two 8 bit sample yield a 16 bit sample.

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Tue Feb 19, 2008 9:55 pm

Chilly Willy wrote: That would make a 9 bit sample, not a 16 bit sample. Interleaving ADDS the samples. Two 8 bit samples added together gives a 9 bit sample. You would need a method of multiplying the samples to make two 8 bit sample yield a 16 bit sample.
Hehe, well I forget a step. You need to play the lower eight bit part of the 16bit sample at half the volume and the upper part at full volume.

I've seen this method in action with as low as 7hz interrupt to playback 3.5khz at double the bit rate. I would have never thought it effective at that lower of rate.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 20, 2008 12:09 am

tomaitheous wrote:
Chilly Willy wrote: That would make a 9 bit sample, not a 16 bit sample. Interleaving ADDS the samples. Two 8 bit samples added together gives a 9 bit sample. You would need a method of multiplying the samples to make two 8 bit sample yield a 16 bit sample.
Hehe, well I forget a step. You need to play the lower eight bit part of the 16bit sample at half the volume and the upper part at full volume.
Hmm... so you change the volume on every sample... that should work. Now if someone would try it, we'd see how theory compares to reality. :D

IIRC, the volume is log, so you'll have to remember to chose a volume that corresponds to 1/2 linear.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed Feb 20, 2008 6:30 am

There's no HW way to change volume of the PCM channel...
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Feb 20, 2008 7:33 am

Half volume will cost only one additional operation for Z80 in play loop, any other will cost 256 bytes for table and two operations. But I think, this method with interleaving samples will just sounds bad, so it's better to test it before making any calculations and planning.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 20, 2008 8:39 pm

Shiru wrote:Half volume will cost only one additional operation for Z80 in play loop, any other will cost 256 bytes for table and two operations. But I think, this method with interleaving samples will just sounds bad, so it's better to test it before making any calculations and planning.
It partly depends on having a low-pass filter on the output. The Amiga used this type of "mixing" quite a bit, but you had a low-pass filter on the output unless you turned it off using the LED line. Obviously, the sample rate needs to be high enough that the low-pass filter ends up summing the interleaved samples. The Amiga could do that easily. I'm not sure if the Genesis could.

I agree with Shiru, here - make a simple (hard-coded) test to see how interleaved samples sound before trying to make a player based on it.

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Wed Feb 20, 2008 11:43 pm

True, it should be tested first. I have no plans to immediately write a player (got my hands full with a bunch of other projects).

Though, given that I've seen this method working fairly decent on a 7khz timer to playback 3.5khz with double the bit rate by interleaving, I'm fairly certain 32khz is high enough to playback the double bit rate for 16khz. But then again, that was on different hardware.

Also, there's no hardware volume specifically for channel 6? Or is that just in DAC mode? If not, then you should be able to work around that issue by shifting the lower 8bit part(only, not the MSB) to the right one bit. That will get half the volume for the lower part, but at the cost of outputting 15bit instead of 16bit audio. Not a bad trade off though.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Feb 21, 2008 6:08 am

tomaitheous wrote: Also, there's no hardware volume specifically for channel 6? Or is that just in DAC mode? If not, then you should be able to work around that issue by shifting the lower 8bit part(only, not the MSB) to the right one bit. That will get half the volume for the lower part, but at the cost of outputting 15bit instead of 16bit audio. Not a bad trade off though.
No, it wouldn't. Think about it - sample 1 goes from 0 to 255, but sample 2 goes from 0 to 127. That's not remotely the same thing as sample 1 going from 256 to 65535, and sample 2 going from 0 to 255. If both samples are at the same volume, the samples are added - period. That means you get a maximum of 9 bits of resolution. The point of changing the volume was to adjust the range the sample covers to extend the resolution.

That reminds me - when changing the volume, it wouldn't be 1/2 volume either for the same argument I made above. The volume of the high byte sample must be 256 times the volume of the low byte sample. On log volume, that would be like 1/8, not 1/2.

EDIT: A quick check of the ym2612 docs shows no master volume. The docs say that the only thing that affects the DAC is the Left/Right select bits. So that idea of using the volume to give ~16 bit samples is dead. :(

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Thu Feb 21, 2008 9:02 am

Chilly Willy wrote:
tomaitheous wrote: Also, there's no hardware volume specifically for channel 6? Or is that just in DAC mode? If not, then you should be able to work around that issue by shifting the lower 8bit part(only, not the MSB) to the right one bit. That will get half the volume for the lower part, but at the cost of outputting 15bit instead of 16bit audio. Not a bad trade off though.
No, it wouldn't. Think about it - sample 1 goes from 0 to 255, but sample 2 goes from 0 to 127. That's not remotely the same thing as sample 1 going from 256 to 65535, and sample 2 going from 0 to 255. If both samples are at the same volume, the samples are added - period. That means you get a maximum of 9 bits of resolution. The point of changing the volume was to adjust the range the sample covers to extend the resolution.

That reminds me - when changing the volume, it wouldn't be 1/2 volume either for the same argument I made above. The volume of the high byte sample must be 256 times the volume of the low byte sample. On log volume, that would be like 1/8, not 1/2.

EDIT: A quick check of the ym2612 docs shows no master volume. The docs say that the only thing that affects the DAC is the Left/Right select bits. So that idea of using the volume to give ~16 bit samples is dead. :(
Oh crap, you're right. I was confusing the volume value/parameter with the PCM driver I was writing/test as being almost one half. But the volume is also log in the test run I did. One channel is Max at log($1f) and the other channel much less than half at log($0B). That's what I get for staying up all night :?

Okay. It's late. I have two questions. In the software manual I saw that DAC and FM channels can be set to left/right/both(but no other details). Is this a dual volume setup? Like one parameter/value/nibble is for the left channel volume and the other for the right channel volume(i.e. pan volume)? And is it log? The idea would be to set both right and left together with the same value to get a make shift volume for the DAC channel.

The other is for PWM. It should be possible to set the PSG volume to the desired level since it's log. Couldn't you output a 7 or 6bit sample via PWM for one interleaved slot, then have the z80 output the higher sample portion at full volume to the YM DAC on the next interleaved slot - giving the z80 more time to do something else during the YM DAC writes.

Both would still use the interleaving method.

I'm out of ideas after that :D

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Thu Feb 21, 2008 9:39 am

YM2612 panning works quite simple. Output from each channel (DAC or FM - does not matter) can be directed to left only, right only, both channels, or no channels. I.e. there is only 3 fixed pannings without any 'left/right volume'.

YM2612 does not have 'channel volume' parameter at all, by the way. It has TL parameter for each of four operators of channel, and output volume of channel defined by TL's of 'slots' (operators which connected to output of channel). So, to set channel volume you must change TL's of few operators, from one to four depending from channel algorithm.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu Feb 21, 2008 6:40 pm

But TLs are useful only for FM... BTW, how can you play samples using an FM operator ? I know it can be done.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Post Reply