I thought an authoritative answer could be a valid reason to bring this thread back from the dead, be it just for education or further inspiration. I also had to correct myself, it bugged me.
The core line in SFXR is this:
Remember that p_base_freq is expressed in a range of 0…1. Examining the code further reveals that fperiod is not exactly the period, but 8 times supersampled. Let me reflect this:
Also, fperiod is expressed in terms of the sample rate, that means that at a sample rate of 44100 Hz a period value of 44100 means a sound of 1 Hz. It means that fperiod = SR/f, with f = frequency of the sound and SR = sample rate.
You can use the formula (1) directly, with SR = 44100, to calculate the correct value to feed into SFXR.
Quick check: With f = 130 Hz (note C3) the result is p_base_freq = 0.19. KMEB is right. We have a formula for converting a frequency to an SFXR base frequency value.
Next step: Let’s ignore the slight offset of 0.001 and write the square root as a power.
Express the frequency using a MIDI note. The basics are:
n : MIDI note
N : base note for this formula (your choice)
fN : frequency of fN
use for example:
N = 69 (note A4)
fN = 440
or as KMEB did:
N = 48 (note C3)
fN = 130
Insert f into (2) and simplify:
Using KMEB’s choice we get (keep in mind that n is the MIDI note number, therefore n-48, whereas KMEB sets C3 to number 0):
Phew, it’s time to say “and that’s it”.