sound

4 channels. Each generates square wave, possibly with noise. Or simplify a bit and have 3 square wave channels and a noise channel, similar to the SN76489 which many home computers and arcade games used. Volume 0..63. Maybe 16 instead, that way we need to store fewer bits.

Mix channels together by adding. Resulting value 0..252. Frequency is generated by counting every clock tick and toggling the channel when the count reaches a specified 12-bit value.

If we take the clock frequency to be 7.15909 and use 128 clock cycles per loop, we get a loop frequency of 55930.3Hz.

Note True f Actual Div Error
C0 16.36 16.36 3419 0.10
A0 27.50 27.50 2034 0.11
A1 55.00 55.00 1017  
A2 110.00 110.01 508  
A3 220.00 220.20 254  
C4 261.63 261.36 214 1.26
C#4 277.19 276.88 202 1.34
D4 293.67 292.83 191 3.45
D#4 311.13 310.72 180 1.57
A4 440.00 436.95 128 8.34
A#4 466.17 466.08 120 0.22
B4 493.88 490.61 114 7.96
C5 523.25 522.71 107 1.24
C#5 554.38 553.76 101 1.34
D5 587.34 582.60 96 9.72
D#5 622.25 621.44 90 1.55
E5 659.25 658.00 85 2.28
F5 698.47 690.49 81 13.78
F#5 740.00 735.92 76 6.63
G5 784.00 776.81 72 11.06
G#5 830.62 822.50 68 11.79
A5 880.00 873.91 64 8.34
A#5 932.34 932.17 60 0.22
B5 987.77 981.23 57 7.97
A6 1760.01 1747.81 32 8.35
A#6 1864.71 1864.33 30 0.24
B6 1975.51 1928.62 29 28.83
C7 2093.01 2071.48 27 12.41
C#7 2217.51 2151.15 26 36.46
D7 2349.31 2330.42 24 9.69
D#7 2489.01 2431.74 23 27.93
E7 2637.01 2542.27 22 43.90
F7 2793.81 2796.50 20 -1.15
F#7 2960.01 2943.68 19 6.64
G7 3136.01 3107.22 18 11.07
G#7 3322.41 3290.00 17 11.76
A7 3520.01 3495.62 16 8.34
A#7 3729.31 3728.67 15 0.21
B7 3951.15 3728.67 15 69.55
C#8 4434.90 4302.31 13 36.42
D#8 4978.01 4660.83 12 79.00
E8 5274.01 5084.55 11 43.90
F8 5587.70 5593.00 10 -1.14
F#8 5919.90 5593.00 10 68.16
G8 6271.90 6214.44 9 11.04
G#8 6644.90 6214.44 9 80.37
A8 7040.01 6991.25 8 8.34
A#8 7458.61 6991.25 8 77.65
B8 7902.11 6991.25 8 146.96