Poor Man's Pitch Correction (Chromatic Quantization)
Now that I thoroughly understand the linear to exponential business on the pitch side (really have to do this stuff in an interactive spreadsheet) it hit me yesterday that I could use basically the same non-linear process I'm using to improve the readability of the LED tuner to quantize the pitch itself (ala the Theremini).
To do so we need to temporarily offset the tuner side NCO input value with a constant so that it lines up with the binary 5.27 format to isolate / extract the sub-note info and non-linearly process it. Working backwards from C0 NCO output through EXP2 to the linear tuner side, we shift the value left 5 places (% 2^32) to find the octave fraction, then multiply by 12 (% 2^32) to find the sub-note fraction. We then undo this by dividing by 12 (umult by 2^32 / 12) and shifting right 5 places, giving the constant value 8524950, or 0x821496.
To use it we subtract the constant from the NCO input value, and then separate out the octave, note, and sub-note values using the same shifts and multiplications we used to find the offset constant. At this point we can non-liearly process the sub-note value, then recombine the octave, note, and non-linear subnote values, and finally add the constant back.
For the non-linear sub-note quantization function itself, I've picked a simple power here (described in a previous post). The input slope is folded down (logical NOT) when the input exceeds 1/2, which gives a triangle. We multiply this by 2 to get an output range of [0:1), multiply it by itself a number of times (the power here sets the quantization strength), divide the result by 2, and the output is flipped (logical NOT) if the input exceeds 1/2. XOR may be employed to do the logical NOT, and shifts for the multiplication and division. Decimal powers could also be implemented, though integer powers seem to give sufficient control over the process, and are much less expensive in terms of processor cycles.
So I've implemented this on the prototype and it works pretty much as expected. Squaring gives quite mild quantization, 4th power is getting stronger, 8th and above is pretty strong, but even going way above this there isn't any hard "stepping" sound. Not sure if I'll use it much, particularly as it kind of kills on-note vibrato (and accentuates off-note vibrato!) but it was an interesting thing to try out. It's a first stab at actual pitch correction, which I believe uses more of a quantized PLL approach to things.
=============
It's kind of a shame they didn't use 1Hz as the frequency basis of our note system, because it's already pretty close to just a 4 octave offset (16Hz) from C0 (~16.3516Hz). C0 is only ~2.2% or ~37 cents above 16Hz. (If we could go back in time and change things I'd pick note numbering rather than lettering, with C=0, and with chromatic rather than C major scale based intervals.)