YM2612 Envelope generator question

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

Moderator: BigEvilCorporation

Post Reply
vecna
Newbie
Posts: 4
Joined: Thu Aug 09, 2012 4:10 am
Contact:

YM2612 Envelope generator question

Post by vecna » Thu Aug 09, 2012 5:09 am

So, I'm working on a YM2612 core based pretty much exclusively on the information in this forum (I'm trying very hard to avoid referencing MAME). When I was first getting the basic shell functioning, I made an extremely basic test rom that played one note:

* Alg#7, only on operator 4 - should be pure sine
* AR $1F, no attack phase. KS=0.
* DR=4
* SL is 4, so normalized to a 10 bit attenuation value, it should switch to sustain at an attenuation value of 128.
* SR is $10 so once it switches to sustain the note ends very rapidly.
* My TL is $13, though I don't believe this should matter.

The issue I noticed was that the note played noticeably longer in my emulator than in KEGA. I kept looking for an error in my code and never found it - It appears to correct based on the information in page 8 about the envelope generator.

In my emulator it took ~7.4 seconds from key-on to the sustain phase.
In KEGA, Regen, and in MAME (genplus-gx version), it took ~5 seconds (to be exact, it took 87040 EG cycles in genplus-gx).
Interestingly enough, in GENS it took ~4.5 seconds.

So, here's my math.
DR=4,KS=0, means my Rate is 8.
That means my shift value is 9, so it takes 512 EG cycles per EG update tick.
At rate 8, there is a total of 4 attenuation gain per 8-cycle group.
SL=4 means we need to gain 128 attenuation.
So it should take (128/4)*8*512 EG cycles to complete the decay phase. That works to 131072 EG cycles or 7.38 seconds.

I tested on my Everdrive and the result was... it took 5 seconds.

Here is my test ROM. https://dl.dropbox.com/u/2253413/simpletest.bin

I just now tested on some version of Exodus that I found buried in these forums somewhere, and it took ~5 seconds. I'm assuming that Exodus should match the behavior described on page 8, so I assume that the information is correct but I'm just misunderstanding it. But I'm totally at a loss as to what I'm not understanding. The rate calcs and example code seem quite clear.

Any guesses at what I'm missing? What part of my math is wrong?

vecna
Newbie
Posts: 4
Joined: Thu Aug 09, 2012 4:10 am
Contact:

Post by vecna » Thu Aug 09, 2012 5:50 am

Bleh! Lying in bed, trying to fall asleep... of course the answer comes to me.

The rate is not 8.

RKS is not an abbreviation for Rate/KeyScale. The rate is 10, and then the math all works out.

I'm dumb.

I can't delete the post so I'll leave this record of my dumbness for all to see!

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

Post by Stef » Thu Aug 09, 2012 8:33 am

Hehe sometime writing the problem can help to sort it out :)
Well interesting enough, as you said, Gens timing is a bit different... I wonder why as i heavily used MAME as reference for almost of the timing used. Anyway hopefully that bug does not affect much general sound emulation.

Post Reply