Gens HEX Frequency to Hertz or Note Value? (YM2612)

Discussion in 'Engineering & Reverse Engineering' started by Noah Copeland, Nov 1, 2019.

Tags:
  1. Noah Copeland

    Noah Copeland

    Member
    29
    11
    3
    Looking at the Ym2612 debug menu in GensKmod. The "Frequency" seems to be the pitch value that the channel is playing.

    example:
    [​IMG]

    Does anyone know how these values translate into something more musical like Hertz or standard musical notation?
     
  2. MarkeyJester

    MarkeyJester

    My predecessors have nothing on me. Resident Jester
    I have recorded several frequencies from my hardware with an operator's multiply set to 1, recorded at 44,100Hz, 16-bit. So my results are based on that, and that alone.

    A channel frequency of 0x7FF has 51 full cycles, each full cycle is approximately 857 samples, the last incomplete cycle is 423 samples, this is 0.4935822637106184 of a cycle. 0x7FF = 51.4935822637106184 cycles (Hz).

    A channel frequency of 0x100 has 6 full cycles, each full cycle is approximately 6849 samples, the last incomplete cycle is 3017 samples, this is 0.4405022631041028 of a cycle. 0x100 = 6.4405022631041028 cycles (Hz).

    I cannot do a channel frequency of 0x001, this is because of mechanisms of the hardware which are attempting to smooth out the resulting waveform, it's a DC correction mechanism which always tries to push the wave towards DC offset 0. I am to believe through research, this is to prevent electronic interference, but I have no confirmation yet, but a lot of electronic items have this mechanism. What this means for us though, is that recording a frequency of 0x001 will show NO cycles at all, the mechanism smooths it out towards 0 too effectively because of how slow the wave is attempting to push away from 0.

    Using the other frequencies, I can get you a predicted "approximation" of what 001 would be.

    51.4935822637106184 / 0x7FF = 0.0251556337389891
    6.4405022631041028 / 0x100 = 0.0251582119652504

    So a channel frequency of 0x001 should have approximately 0.02515 cycles (Hz).

    You do have to keep in mind however, that there are issues with recording analogue from old hardware which interfere with the results, for example the above DC correction mechanism can cause spikes to appear if the frequency is small enough, and noise can be an issue, it makes it difficult to get an exact figure. The frequency 0x100 had both for example, so what you've got is nothing more than an approximation.

    In relation to musical notation, well, you would technically use the Hz to decide that. But just for reference, I can at least give you an example of what the Sonic games use for each notation:

    Sonic 1 for example: C = 2AB | C# = 2D3 | D = 2FE | Eb = 32D | E = 35C | F = 38F | F# = 3C5 | G = 3FF | G# = 43C | A = 47C | B = 25E (Octave up by 1)
    Sonic 3 for example: C = 2AB | C# = 2D3 | D = 2FE | Eb = 32D | E = 35C | F = 38F | F# = 3C5 | G = 3FF | G# = 43C | A = 47C | B = 4C0

    Note that 4C0 on one octave, and 25E on the next octave up can yield similar if not exact rates/pitches. The octave is more of a power factor. Octave 0 Frequency 0x400 = 0x400, Octave 1 Frequency 0x400 = 0x800, Octave 2 Frequency 0x400 = 0x1000, and so on. So there are technically two ways to achieve the low/high end notes, you can use a lower frequency of the next octave, or the high frequency of the previous octave.

    Because our ears are logarithmic, the higher the note, the larger the frequency change. So higher frequencies will allow you more precise and flexible pitches, however, you'll have less range for changing between notes because the frequency changes required to achieve the next note are way too high and will overflow the 0x7FF range before you reach it. Likewise, lower frequencies allow you quicker changes between notes, so you can access all the notes you need, the drawback is, there's less precision between the notes so you will have less pitch bending or detune availability. The ranges which SEGA used above would've been chosen likely based on balance, they are in the middle, Sonic 3 they likely believed that using a higher frequency 4C0 to achieve B rather than the next octave lower frequency 25E to achieve B allowed them more precision when bending the pitch to the next octave.

    Different games for the system may have had slightly different frequencies, I cannot tell you if the above frequencies are correct, we could perhaps use 0.02515Hz for each frequency and work out what the ideal frequency should be, but again, this Hz is just an approximate based on recordings, and the hardware's nature makes it difficult to get an accurate recording without modifying the hardware to some degree.
     
  3. Noah Copeland

    Noah Copeland

    Member
    29
    11
    3
    Using Flying Battery's bass line, this is what I saw for a few notes in Gens debug menu
    F - 0x035C
    G = 0x03C5
    G# = 0x03FF
    A = 0x043C

    Markey, you'll have to forgive my ignorance. What is the relation to the values you provided to the way its displayed in Gens debug menu?
     
  4. Natsumi

    Natsumi

    Miss Fox Tech Member
    192
    2
    18
    Long and dangerous river
    Navigating said river
    He listed the notes in the middle of his post. The note sequence you listed isn't really the way we tend to think of the notes, and here is what the sequence would look like to sound programmers: E, F#, G, G#. If you look at Markey's post, these values are directly lifted from his post. However, FM also has the octave part in its value too. This may appear either as, for example, 0x0AAB for C1, or as 0x02AB, octave 0x02 (or 0x01, I actually can't remember). It depends on the emulator. In technical terms, the frequency is 0xAAB, as that is what is being sent to YM2612 directly. Often, the frequency and octave values are more or less just invented by sound programmers as good enough approximations for most instruments. Various settings in the YM2612 will alter this pitch and may make the instruments sound as different key regardless of frequency. Other tricks, such as frequency modulation, detuning, and pitch slides are able to alter the note off-key, so you have to really just approximate what they key might be from the values in any YM2616 debugger. For SMPS games, either of the 2 frequency lists are used as the base frequency of each key, and usually modulation and any other tricks will just offset the raw frequency in a linear fashion, no care is taken to make the frequency changes logarithmic or proportional.
     
  5. Noah Copeland

    Noah Copeland

    Member
    29
    11
    3
    I mean, yeah, I saw this. But did not understand why the perceived pitch of said values were a semitone apart from the listed value.


    Ah. There it is. Just a lot of fiddling and approximating I see. No translatable or proportionate ratio exists. Cool. Good to know. I'll go back to measuring sounded YM2612 frequencies with pitch detection software to get down to the cents.

    Thanks you two! :thumbsup:
     
  6. Natsumi

    Natsumi

    Miss Fox Tech Member
    192
    2
    18
    Long and dangerous river
    Navigating said river
    Well, I just clarified the bit that I understand, as I wasn't sure what exactly you were asking about (I suppose I got the wrong idea from your post). I don't know the all technical details behind how YM2612 generates audio and certainly not enough to relate it to a more familiar format (Hz for example), nor do I know to which degree this is understood by people in general. I think Markey may be able to give a more precise answer.
     
    Last edited: Nov 6, 2019