Stereo DAC on YM2612

Announce (tech) demos or games releases

Moderator: Mask of Destiny

MarkeyJester
Newbie
Posts: 1
Joined: Sat Mar 26, 2011 7:35 pm

Stereo DAC on YM2612

Post by MarkeyJester »

Hello there, allow me to introduce myself.

I go by the name of MarkeyJester and I am usually found hanging around on SonicRetro frequently, I don't usually browse or acknowledge SpritesMind (sorry), however a discussion on an irc channel on badnik.net about "Stereo" DAC playback lead me to being advised to share this here.

We were discussing PCM sample playback on the YM2612 and quality differences, when one individual noted that "Stereo" sample playback was not possible except the direct speaker choice (Left, Right or Both), in order to prove otherwise I wrote and assembled an MC68k software controlled PCM playback system.

by using a method of switching the FM6 panning to left speaker, flushing the left speaker PCM byte to the DAC channel port, then switching the FM6 panning to right speaker, and flushing the right speaker PCM byte to the DAC channel port, simultaneously in a loop. With MC68k being a fast enough processor, I was able to have it play a 44,100 mhz stereo 8-bit (just under 1 minute) music track by Duran Duran.

"andlabs" a user in the channel at the time suggested that you people here at SpritesMind would be interested in this. So I've decided to comply with that and registered to make this post.

http://mrjester.hapisan.com/00_PRVT/PCM.rar

here is a link to the source code along with a pre-built rom, it works reasonably well in Kega, Gens seems to have issues with it though, but on real hardware it's turned out more crispy and in more brilliant quality than I expected myself (I guess it goes to show how bad Mega Drive emulators are at emulating PCM playback).

I'd also like to pardon my ignorance, as I said, I don't usually read these forums and although I ran a quick (although non-thorough) search, I didn't find any topics similar to this, I do apologise if this is not something any of you are interested in or if it's something that happens to be last year's old news.

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

Post by TmEE co.(TM) »

It suffers from the same problem on real hardware as my experiments that I did long ago. Gens sounded closest to real HW than other emulators I tested back then.

As long as there's not much channel spearation then it would sound fairly good but the greater the difference between channels the worse things go.

I got better results when I played i.e 16 samples on one side then 16 on another etc. It reduces the staticness a bit but is still far from optimal.
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
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

I suggested this very thing for stereo PCM quite a while back, but was informed by Tiido that his experiments doing that were less than encouraging (as his post before mine covers). It doesn't sound too good on real hardware... it's about as noisy as my 8:1 compression. The switching on the channel is evidently not very clean - it sounds a lot worse than you'd expect for an equivalent stream of

Code: Select all

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

Post by TmEE co.(TM) »

The problem is that when you switch the channel you have things still outputting sound and L ends up in R and the other way. Only way to avoid it is to somehow do things with YM cycle accuracy, BUT if you even think of accessing ROM or anything else outside of Z80 memory space the timings go whack and you get nowhere.
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 »

I could take a guess that the things could be improved if you do it this way:

- set to left
- output a value
- wait a bit
- output 0
- the same for right

This way you'll not carry output of one channel to other, and these 0's just reduce the volume if this code will work as fast as possible - few times per a pair of samples, but not too fast to prevent YM2612 to skip writes.
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

Writing the zero will only increase noise, producing a big spike on the output every time it gets written.

Steve snake suggested using YM timers to get timing synchronous to internal state of the YM but outputting values at an exact multiple of YM output resolution is impossible in MD, moreso because switching the channels takes more than one YM cycle to happen.
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 »

Did you actually tested that? It is basically the same tech Chilly Willy once suggested as one of possible ways to mix two samples (as used on Amiga), and it was successfully used for other things too. These zeros, when you write them on a constant speed, like in this case, will create a carrier, not noise, and if you do it fast enough, you'll move the carrier above the audible range.
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

Yes I have tried it and it only made things worse.

The thing chilly told heavily relies on the very strong low pass filtering present in Amiga (5 or 8KHz cutoff). You cannot have the carrier above audible freq range on MD, the sample rate is 53KHz, but only half of it can be used for PCM updates which is 26KHz, this leaves possible 13KHz freq range, and now when you want to do the zeroes interleave you end up with 7KHz that is well below the cut off range in any MD model.
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
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

That's too bad... funny how this is a case where we WANT strong filtering. :lol:

In this case, you'd have to tell people to turn the treble setting on their amp/TV down - use external filtering to do the job instead of internal filtering.
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

...which translates to : lets put DACs on controller ports or inside the cartridge :P
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
sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 »

TmEE co.(TM) wrote:...which translates to : lets put DACs on controller ports or inside the cartridge :P
Great idea but how would you put a dac on a controller port?I see a cartridge as a possibility.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

sega16 wrote:
TmEE co.(TM) wrote:...which translates to : lets put DACs on controller ports or inside the cartridge :P
Great idea but how would you put a dac on a controller port?I see a cartridge as a possibility.
You see things like that for the C64 and A8 computers. It's really only viable on systems where most of the port lines can be configured for either input or output (in this case, outputs). The MD port lines can be configured as outputs.

The cart DAC for the MD is simple (in theory) - you just have a CPLD which connects to some decent op-amps which then feed the audio in lines on the cart port. More complicated (but better for sound generation) would be to add ram on the cart and use it as sound ram for samples or instruments.
Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru »

Maybe we should attempt to play samples through usual FM channels, using TL changes, before hooking DACs?
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Shiru wrote:Maybe we should attempt to play samples through usual FM channels, using TL changes, before hooking DACs?
That was a suggestion I made some time back... if you set the frequency of the channel low enough or high enough, the TL will act as a modulator and the "carrier" will be filtered out. Haven't done any experiments with that yet.
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

I have done some work on using FM to play samples but it did not quite turn out as I hoped, I did get samples play but the quality left a lot to be desired... perhaps I just did something wrong, who knows :P
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