DPCM playback rate does really correlate with note freqs

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

User avatar
rainwarrior
Posts: 7680
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Post by rainwarrior » Fri May 18, 2012 10:25 pm

I was building a table of the PAL frequencies for the wiki DMC page and I noticed this also fits the same pattern of picking the same set of notes and their closest match to A440, with two glaring exceptions. (The following table lists potential closest matches to A440 among available pitches.)

Code: Select all

DMC   Octave   Note   Cents        
-----------------------------------
0x032 12       C      -12.2401718  ******
0x034 11       B      +19.8595941
0x038 11       A#     -8.43865057
0x03C 11       A      -27.8814588
0x03E 11       G#     +15.3516834
0x042 11       G      +7.11431267  ******
0x046 11       F#     +5.24763556
0x04A 11       F      +9.04321714
0x04E 11       E      +17.9045932  ******
0x054 11       D#     -10.3936514
0x058 11       D      +9.06931353
0x05E 11       C#     -5.11936612
0x062 11       C      +22.7354429  <- ???
0x064 11       C      -12.2401718  <- Why not this?
0x06A 10       B      -13.1172895
0x070 10       A#     -8.43865057
0x076 10       A      +1.21559666  ******
0x07E 10       G#     -12.3486523
0x084 10       G      +7.11431267  ******
0x08C 10       F#     +5.24763556
0x094 10       F      +9.04321714  ******
0x09E 10       E      -4.14964192
0x0A6 10       D#     +10.3399382
0x0B0 10       D      +9.06931353  ******
0x0BC 10       C#     -5.11936612
0x0C6 10       C      +5.15931180  ******
0x0D2 9        B      +3.29263470  ******
0x0DE 9        A#     +7.08821628
0x0EC 9        A      +1.21559666  ******
0x0FA 9        G#     +1.44611430
0x10A 9        G      -5.95166671  <- Why not this?
0x114 9        F#     +30.1579077  <- ???
0x118 9        F#     +5.24763556
0x12A 9        F      -2.61496866  ******
0x13C 9        E      -4.14964192  ******
0x14E 9        D#     -0.05789507
0x162 9        D      -0.73940420  ******
0x176 9        C#     +4.11390403
0x18E 9        C      -3.56228876  ******
Did they really get it wrong like this when building the 2A07, or is the information on the wiki incorrect? If I had a PAL NES to test I'd verify it myself, but as I can't, can anyone else verify it for me?

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Post by lidnariq » Fri May 18, 2012 11:48 pm

I believe Quietust had said that the tables didn't exist as a conventional LUT but were instead the result of a tuned LFSR. I don't know what kind of magic is involved in packing short LUTs into even smaller LFSRs, but maybe that's why?

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat May 19, 2012 5:35 am

It's ordinarily a 1:1 conversion from binary to Galois domain. Either there is a typo on the wiki or there was a typo inside Nintendo or Ricoh. Only a test ROM would distinguish these cases. Should I be the one to make it?

User avatar
rainwarrior
Posts: 7680
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Post by rainwarrior » Sat May 19, 2012 11:04 am

Made this quickly in FamiTracker:
dpcm_pitch_test.nsf (dropbox link removed, file lost)

It's just a 17-byte looped triangleish bass. An audio recording of this from a PAL NES should be enough to measure the wavelength to determine the correct values.[/url]
Last edited by rainwarrior on Mon Aug 07, 2017 3:06 pm, edited 1 time in total.

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Post by lidnariq » Sat May 19, 2012 1:31 pm

tepples wrote:It's ordinarily a 1:1 conversion from binary to Galois domain.
Tepples, do you have a link I could read about this? Ideally without involving graduate-level math?

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat May 19, 2012 5:12 pm

Clocking an LFSR is equivalent to multiplying by x in a finite field. Probably the most accessible description of how multiplication works in a finite field, the one I read when first trying to understand how Reed-Solomon error correction works, is "Finite field arithmetic" on Wikipedia. It's not graduate math, but it might be undergraduate math. And if you do anything with RS codes, you'll have to wrap your head around it sooner rather than later.

An 8-bit LFSR operates in the finite field GF(256). (Here, I use "integer" for an ordinary whole number and "bit pattern" for an element of a finite field.) What you're looking for is the number that when multiplied by 00000010 n times results in 00000001, so because 00000010 to the 255th power is 00000001, you'll want to take 00000010 to the power of (255 - n).

Please let me know which sentence in this post was the first sentence that you failed to understand.

There are ways of calculating the powers of 00000010. One is to build a lookup table from integers n to bit patterns 00000010^n. Building this table requires O(n) multiplications, but the resulting "log table" can be reused at O(1) each for multiple entries, such as the 32 entries in the length counter LUT or the 16 entries in the noise or DMC period LUT. The RS module in a typical QR barcode library generally uses this method for GF(256). The other, which is faster but may be hard to understand for people who don't know finite fields well, is exponentiation by squaring. This requires only O(log n) multiplications per table entry that's actually used.

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Post by lidnariq » Sun May 20, 2012 12:29 pm

tepples wrote:What you're looking for is the number that when multiplied by 00000010 n times results in 00000001, so because 00000010 to the 255th power is 00000001, you'll want to take 00000010 to the power of (255 - n).
Under what conditions is (00000010 ≅ x)²⁵⁵ ≡ 1 mod 256? 256 isn't prime, and I don't see a reducing polynomial mentioned. If we need to find such a polynomial, how do we find both the reducing polynomial and the seed at the same time? If we don't, what's going on?
There are ways of calculating the powers of 00000010. One is to build a lookup table from integers n to bit patterns 00000010^n. Building this table requires O(n) multiplications, but the resulting "log table" can be reused at O(1) each for multiple entries, such as the 32 entries in the length counter LUT or the 16 entries in the noise or DMC period LUT.
Am I mistaken in thinking that there is only one set of taps (the reducing polynomial) and the LFSR just loaded in a seed and then was clocked N times?

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun May 20, 2012 8:58 pm

lidnariq wrote:Under what conditions is (00000010 ≅ x)²⁵⁵ ≡ 1 mod 256?
Under any reducing polynomial with x^8 as the highest order term.
If we need to find such a polynomial
The taps determine the reducing polynomial.
Am I mistaken in thinking that there is only one set of taps (the reducing polynomial) and the LFSR just loaded in a seed and then was clocked N times?
There exist more than one primitive reducing polynomial for each field size, and some field sizes need more than two taps. That is, there exist more than one valid set of taps for each LFSR length. One can find tables of such polynomials for each order. But even though (say) QR and DataMatrix use different polynomials, people speak of "the" GF(256), or "the" finite field with 256 elements, because there's an isomorphism between any two fields of the same order with different polynomials.

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Post by lidnariq » Mon May 21, 2012 11:33 am

tepples wrote:
Am I mistaken in thinking that there is only one set of taps (the reducing polynomial) and the LFSR just loaded in a seed and then was clocked N times?
There exist more than one primitive reducing polynomial for each field size, and some field sizes need more than two taps. That is, there exist more than one valid set of taps for each LFSR length. One can find tables of such polynomials for each order. But even though (say) QR and DataMatrix use different polynomials, people speak of "the" GF(256), or "the" finite field with 256 elements, because there's an isomorphism between any two fields of the same order with different polynomials.
Sorry, what I meant was, "In the silicon, is each LUT one specific seed and one specific set of taps and entry N is contents of the LFSR when clocked N times?" You explained how to find the seed given the taps; is there an method for finding the taps?

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Mon May 21, 2012 12:09 pm

lidnariq wrote:In the silicon, is each LUT one specific seed and one specific set of taps and entry N is contents of the LFSR when clocked N times?
In the silicon, there is only one set of taps, used for all LUT entries. Each entry is 00000010^(INT_MAX - n).
You explained how to find the seed given the taps; is there an method for finding the taps?
The taps depend on the length of the LFSR. A table of taps for each length can be found in any book on finite field theory, and there are online tools to find them. For most lengths, two or four taps are used. For example, the polynomial x^8 + x^4 + x^3 + x^2 + 1 is primitive, and it leads to an 8-bit 4-tap LFSR. That polynomial corresponds to the entry 1 0 0 0 1 1 1 0 1 when you tell the tool to generate "Primitive polynomials over GF(2), n = 8".

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 488
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Post by Jarhmander » Sun Jun 10, 2012 8:51 pm

Sorry for the bump. Got back to a question from bucky o'hare.

Well, why did they choose these notes? Well, C-D-E-F-G-A-B-C (speed 0-8) is the major C scale, and C-E-G-C is a major C chord (speed 12-15), but what about C-D-F-G-A-C (speed 8-12) ?

First thing to note is that it's a kind of a scale, the pentatonic scale (F pentatonic scale to be more precise). The special thing about it is that it doesn't have any semitones or tritones, so it always sounds good. I noticed that the church's bells are C-D-F-G-A-C at the one near my girlfriend's parents, and it's never dissonant.

More interesting aspect however, is that C-D-F-G-A-C is actually the Slendro scale used in some oriental music (indonesian gamelan music). That might be why these notes were used.

EDIT: removed a non-intentional smiley.

User avatar
rainwarrior
Posts: 7680
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Post by rainwarrior » Mon Jun 11, 2012 10:12 am

Yeah, they could have been going for a pentatonic scale, maybe, though I don't know why they'd pick that particular version of it.

I don't think Slendro is a reasonable candidate, though. Its tuning is very different from 12-TET, and we've already determined that the DPCM frequencies are all tuned to A-440 12-TET. It only looks like the pentatonic scale when you approximate it in 12-TET.

User avatar
rainwarrior
Posts: 7680
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Post by rainwarrior » Wed Jul 25, 2012 5:33 pm

I was finally able to verify the PAL DPCM frequencies from a recording jrlepage made for me with this PAL NES. The table on the wiki is correct, which means those two frequencies which don't match the tuning scheme are actually that way in the hardware. So, I guess they made a mistake when building the 2A07, which is quite interesting.

Post Reply