friture
friture copied to clipboard
Add pitch information
Nice program. It would be very nice if you could add pitch information. A simple conversion using ET would be helpful + the cent offset. Either add it as an axis or information over the cursor.
The formula which converts freq to pitch index is:
pitch_index = round(12log2) mod+ 12 (in [A, A#, B, ..., F#, G, G#]) octave = floor(log2) pitch_cents = (1200log2) mod 100
So if freq_pitch_base = 440hz which is defined as A4, then
e.g., if A5 = 880hz is plugged in then
pitch_index = round(12log2) mod 12 = round(12log2) mod 12 = 0 = A octave = floor(log2 = 5 pitch_cents = 1200*1 mod 100 = 0
84hz ~= E2 gives
pitch_index = 7 = E octave = 2 pitch_cents = -2866 mod 100 = -66.85 cents = 33 cents
So, it is not difficult to calculate the frequencies for the axis and display them or put them over the mouse. It helps greatly to determine the pitch of stuff in the spectrums/grams. Furthermore, you could detect the peaks automatically and add the pitches for them.
The point of this is so the program can be used for musical analysis in real time such as tuning instruments, checking intonation, etc. To be the most useful it should attempt to automatically convert frequency information in to pitches and display them hands off.
What I'd like to see is then when I sing a note, say, and the spectrogram shows the frequency, somewhere on screen I see the pitch I just sung. It could be in it's own box or over the frequency, or on the horizontal axis(since notes will change it should be continuous. If it plots the notes on the time axis and translates them it would provide a good visual reference).
Seems that the formulas got messed up by GitHub's auto-linking. Here's a rewrite in "code" mode:
The formulas which converts a given freq
to pitch index off a freq_pitch_base
(A):
pitches[12] = {A, A#, B, C, C#, D, D#, E, F, F#, G, G#}
pitch_index = round(12 * log2(freq/freq_pitch_base) ) mod 12
octave = floor(log2(freq/16.35))
pitch_cents = round(1200 * log2(freq/freq_pitch_base)) mod 100
bias_cents = pitch_cents > 50 ? pitch_cents - 100 : pitch_cents
Example: freq_pitch_base = 440Hz (A4), if freq = 880Hz (A5) is plugged in then:
pitch_index = round(12 * log2(880.0 / 440)) mod 12 = 0 , pitches[0] ==> "A"
octave = floor(log2(880.0 / 16.35)) = 5
pitch_cents = round(1200 * log2(880.0 / 440)) mod 100 = 0
bias_cents = 0
A5 + 0 cents
Example2: 84Hz (~ E2) gives:
pitch_index = round(12 * log2(84.0 / 440)) mod 12 = 7, pitches[7] ==> "E"
octave = floor(log2(84.0/16.35)) = 2
pitch_cents = round(1200 * log2(84.0 / 440)) mod 100 = -2866 mod 100 = 33
bias_cents = 33
E2 + 33 cents