A simple tuning app listening to a tone at 443 Hz, which is approximately 11.764 cents above the note A4 = 440 Hz.
Previously we've learned how to calculate frequencies for exact pitches in the Equal Temperament tuning system. However in reality, it is not always an easy task to get notes played by real instruments to produce the exact frequencies required, and usually some fine adjustments are required to the instrument to get it "in-tune".
While historically tuning was done by ear, nowadays we often rely on electronic tuning devices to help adjust our instruments. These devices will usually tell you the measured frequency, along with the closest note name and some number of cents indicating how far away from that closest note you are. To calculate cents, we just subdivide the distance between two notes into 100 equal parts.
However, recall that frequencies are on a logarithmic scale in base 2, and so "equal" subdivisions are performed with respect to that scale
rather than on a linear scale. For example, the base-2 logarithmic halfway point between 10 and 20 is around 14.142.
And so to calculate the deviation of some measured frequency f_M from some target frequency f_T in cents, we can use the
following equation:
$$\Huge \text{Cents} = 1200 \times \log_2 \left( \frac{f_M}{f_T} \right)$$
Let's imagine we are programming an electronic tuning device. First, we will allow the user to set the note A4 to any arbitrary
frequency f_A4 from which all other frequencies will be calculated per an Equal Temperament system. You will then be
given a list of measured frequencies f_M, and for each one calculate how many cents it deviates from the closest note.
Input Data
First line is f_A4, the frequency of the note A4 in our tuning system.
The second line is Q, the quantity of testcases.
Q lines will then follow, each corresponding to some measured frequency f_M.
Answer
Should contain Q space-separated values, corresponding to the number of cents each f_M value deviates from the closest
note in the given Equally-Tempered system.
Error should be less than 1e-3.
Example
input data:
500.000
3
500.289
171.745
1681.794
answer:
1.000 -49.992 0.001