General guidelines on working with PSG/YM2612 natively

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

Moderator: BigEvilCorporation

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Sun Oct 05, 2014 2:33 am

neologix wrote:With MIDI almost no one does micro-tuning, so multiplying by 2^(1/12) to get the default frequencies for the 128 MIDI notes for these purposes is safe.
Image
I just don't understand what you said just right now.
But when it comes to playback midi (generate tone from MIDI note) it requires microtonal tuning otherwise you'll get DUMB sound. More than that, Megadrive Sound Drivers USING THAT. Examples: SMPS, GEMS. I can't claim that ALL Megadrive Sound Drivers using it, but it does not mean that you should ignore that.
Image

neologix
Very interested
Posts: 122
Joined: Mon May 07, 2007 5:19 pm
Location: New York, NY, USA
Contact:

Post by neologix » Sun Oct 05, 2014 2:57 am

r57shell wrote:
neologix wrote:With MIDI almost no one does micro-tuning, so multiplying by 2^(1/12) to get the default frequencies for the 128 MIDI notes for these purposes is safe.
I just don't understand what you said just right now.
What I meant was almost no-one uses micro-tuning other than "equal temperament," so my function using the ratio between semitones as 2^(1/12) is acceptable here.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Sun Oct 05, 2014 3:18 am

(Googled alot)
You are right. Why I was so mad hmm... seems like note tables in sega drivers and in my programs confused me alot :(. Btw I know why they there, because you can't get easily 2^(1/12) in sega genesis, so good solution is to build i*2^(1/12) for i from 1 to 11 and then just multiply / divide by 2.
Image

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 05, 2014 3:56 am

Thanks for uploading these values, I'll give em a test run and make sure the pitch is good. I was doing something wrong with my math that made my notes too sharp or too flat, tuner didn't like it.

EDIT: This tuner really sucks. It goes haywire trying to read the notes... but these values are pretty close. Better than what I was coming up with.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 05, 2014 3:45 pm

What causes the annoying sawtooth like tone on the PSG? I got it to go away with the initial tests but now that I have a way to read my sequencer data to find the correct note for the psg... It's come back. I'm only using one PSG tone channel right now at all, I'm getting the normal square wave but also the unchanging A above middle C sawtooth tone. I seem to be sending the data to the psg correctly, otherwise I wouldn't get the square waves at proper pitches and not attenuated. Is it possible that I'm wrong and somehow feeding garbage data to the psg?

The sawtooth signal is present in Regen, and Gens... but not Fusion. It's slightly higher pitched in Gens. I don't think I see anything in documentation about it either.

Jazzmarazz
Very interested
Posts: 60
Joined: Wed Mar 12, 2014 11:11 pm
Location: Michigan
Contact:

Post by Jazzmarazz » Sun Oct 05, 2014 4:24 pm

Count SymphoniC wrote:What causes the annoying sawtooth like tone on the PSG? I got it to go away with the initial tests but now that I have a way to read my sequencer data to find the correct note for the psg... It's come back. I'm only using one PSG tone channel right now at all, I'm getting the normal square wave but also the unchanging A above middle C sawtooth tone. I seem to be sending the data to the psg correctly, otherwise I wouldn't get the square waves at proper pitches and not attenuated. Is it possible that I'm wrong and somehow feeding garbage data to the psg?

The sawtooth signal is present in Regen, and Gens... but not Fusion. It's slightly higher pitched in Gens. I don't think I see anything in documentation about it either.
You may be forgetting a register, or filling one that you don't need by mistake. Again, the damned gameboy register needs about 5 or 6 various writes until I can get a tone out of one channel. Volumes, enables, etc.

Have you muted all other channels prior to writing the square wave data?

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Oct 05, 2014 4:33 pm

Jazzmarazz wrote:
Count SymphoniC wrote:What causes the annoying sawtooth like tone on the PSG? I got it to go away with the initial tests but now that I have a way to read my sequencer data to find the correct note for the psg... It's come back. I'm only using one PSG tone channel right now at all, I'm getting the normal square wave but also the unchanging A above middle C sawtooth tone. I seem to be sending the data to the psg correctly, otherwise I wouldn't get the square waves at proper pitches and not attenuated. Is it possible that I'm wrong and somehow feeding garbage data to the psg?

The sawtooth signal is present in Regen, and Gens... but not Fusion. It's slightly higher pitched in Gens. I don't think I see anything in documentation about it either.
You may be forgetting a register, or filling one that you don't need by mistake. Again, the damned gameboy register needs about 5 or 6 various writes until I can get a tone out of one channel. Volumes, enables, etc.

Have you muted all other channels prior to writing the square wave data?
EDIT: Well I fixed it, it sounded more like a pulse wave now that I think of it. You were right. The init code had stuff in it to fully attenuate all psg channels... but for some reason it wasn't working properly. I'll have to fix that. But now we can use the note editor to play the entire 3rd octave in good pitch. (I still need a good tuner!) But it sounds musically correct. Time to get the other octave tables and channels done too.

I think it was coming from channel 4. How confusing.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Mon Oct 06, 2014 6:44 pm

Let me see if I got this straight.

A04000 - FM1 register select (channels 1-3)
A04001 - FM1 Data

A04002 - FM2 register select (channels 4-6)
A04003 - FM2 Data

These are the YM2612's equivalents to the VDP Control and Data ports right?

So I have to write a byte at a time to the data regs? Also I need to get the 68k z80 handshake before accessing the YM2612... so I need to do this everytime I read or write, correct? I'm going to have to really reread the sound manual numerous times over to understand better how it works.

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) » Mon Oct 06, 2014 7:08 pm

You write the register number to the index port, wait for chip to be ready, then you write data fro that register into the data port and wait for chip to be ready if you are gonna do more writes, if not you can omit that wait.
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

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Mon Oct 06, 2014 8:21 pm

TmEE co.(TM) wrote:You write the register number to the index port, wait for chip to be ready, then you write data fro that register into the data port and wait for chip to be ready if you are gonna do more writes, if not you can omit that wait.
Thanks, this is important to know.

After gleaning over the memory map some more, I finally made sense of things, enough to start working with it. I'm just getting all of my YM globals defined and then I can really get going with this beast.

EDIT: Oh my god... that was a lot of registers to define.
I should be thankful that the same registers used to control Channels 1-3 are also used to control Channels 3-6, that would've been twice as much work. Whew! Ok, time to get a sine wave singing.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Tue Oct 07, 2014 12:15 am

Holy Sh-... the YM2612 sounds so beautiful...

Ahem, anyways 8). After alot of typing, I got a note to play. The only problem I really had was figuring out how to properly do the z80 handshake, but that was a small obstacle.

I have one question. TmEE you said that I have to wait in between writes even if doing more data... Just for clarity, do I need to wait still if I just wrote data to the YM2612 and need to write to the index registers? Or is it only in between data writes?

Jazzmarazz
Very interested
Posts: 60
Joined: Wed Mar 12, 2014 11:11 pm
Location: Michigan
Contact:

Post by Jazzmarazz » Tue Oct 07, 2014 12:24 am

I was worried you were going to say you hit the memory limit and have to give up! Don't scare me like that! Hah...

Glad to hear you ... hear sound. :P Is it about time to edit your main thread with the latest version updates? Can't wait to test a demo for you.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Tue Oct 07, 2014 12:43 am

Jazzmarazz wrote:I was worried you were going to say you hit the memory limit and have to give up! Don't scare me like that! Hah...

Glad to hear you ... hear sound. :P Is it about time to edit your main thread with the latest version updates? Can't wait to test a demo for you.
Hahaha. Well now that I have a note, I'm going to do the note tables for the YM2612 and then code that in (like I did with the PSG) so we can play the whole chromatic scale and not just one note. Then I need to do a couple of bug fixes and get the Tracker info to display the notes that are being played, what channel we're on, what chain we're on... then I think a demo is ready.

Now that I realize, I'm going to have to figure in how much memory I'll need for command tables and instrument data. But that can wait until after the demo.

Jazzmarazz
Very interested
Posts: 60
Joined: Wed Mar 12, 2014 11:11 pm
Location: Michigan
Contact:

Post by Jazzmarazz » Tue Oct 07, 2014 12:49 am

Does the YM have a support for more octaves than the PSG? I was playing with GenMDM this afternoon and some of my MIDI inputs were not sounding on the PSG when they would on the YM. The lower end wasn't supported by the PSG IIRC.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Tue Oct 07, 2014 12:53 am

Jazzmarazz wrote:Does the YM have a support for more octaves than the PSG? I was playing with GenMDM this afternoon and some of my MIDI inputs were not sounding on the PSG when they would on the YM. The lower end wasn't supported by the PSG IIRC.
Yes it does. The PSG's lowest notes bottom out at around the 2nd octave, everything below that makes the PSG play some weird notes on the tracker... I have tested the octave range for the YM on Deflemask but I don't quite remember the octave range... I think it was octaves and notes C#0-C8. I'll learn more after getting the frequency tables hard coded.

It's a shame, because I really like low pitch square waves.

Post Reply