7
I used to play the oboe, the instrument that is, for some reason, used to tune the orchestra to A440. Anyways, continuing on with my story, I was bad at it and quit.
Write a program that generates a valid, full scale, 5 second, WAV file with a sample rate of 44.1 kHz that plays a 440 Hz (+3/-1 Hz) tone. Your code is responsible for generating the structure of the file format; no external resources.
+75 penalty if the tone does not approximate a sine wave (harmonic power must be less than 1% of the fundamental--a good polynomial approximation should be able to exceed 20 dB; I think parabolic is about -28 dB)
2
define "sine wave". Is it okay if I use a truncated triangle wave, a parabolic wave or (say) a 20-line approximation, or I have to get it right within a few ULP?
– John Dvorak – 2014-02-05T12:41:35.4272Specifically, having a measurable metric as part of the goal (say, using Audacity spectral analysis) would be optimal. – Tobia – 2014-02-05T13:10:00.583
Can you clarify rules for amplitude? Does it have to be 0 dBFS? Or, taking it to the extreme, can I use only 1 bit, and just toggle the bit 880 times a second? – TypeIA – 2014-02-07T22:14:05.347
@dvnrrs yeah, full scale is basically what I was going for in saying "audible" (was trying to avoid 1 LSB WAVs). – Nick T – 2014-02-08T03:17:38.107
@Tobia I loosened "sine" to be things that are very-nearly-sinusoidal, if a polynomial or other approximation would work better. – Nick T – 2014-02-08T03:25:42.513