## Amazing Grace

Charlie Veniot 1st January 2023 at 4:38pm
``````_INITAUDIO
<<include "Hz#(note\$)">>
t = 5
sndwave\$ = "sine"

SUB s(n\$,d#)
SOUND Hz#(n\$), t*d#
END SUB

main_start:
stop_song\$ = ""
_SNDWAVE sndwave\$
GOSUB playsong
_KEYCLEAR
WHILE (NOT _AUDIODONE) AND stop_song\$ = ""
PRINT "song is playing; press a key at anytime to stop the song."
stop_song\$ = INKEY\$
_DELAY 1
WEND
IF stop_song\$ <> "" THEN _ENDAUDIO
PRINT "Play song again?  Y or N" : answer\$ = UCASE\$(INPUT\$(1))
PRINT "current tempo is: " + t
temp\$ = ""
DO
PRINT "enter a new tempo between 1 and 9"
temp\$ = INPUT\$(1)
LOOP WHILE VAL(temp\$) < 1 AND VAL(temp\$) > 9
t = VAL(temp\$)
temp\$ = ""
DO
PRINT "choose a waveform: (1) sine (2) square (3) triangle (4) sawtooth
temp\$ = INPUT\$(1)
LOOP WHILE VAL(temp\$) < 1 AND VAL(temp\$) > 4
SELECT CASE temp\$
CASE "1"
sndwave\$ = "sine"
CASE "2"
sndwave\$ = "square"
CASE "3"
sndwave\$ = "triangle"
CASE "4"
sndwave\$ = "sawtooth"
END SELECT
DO
PRINT "choose a sound fading option: (1) none (2) linear (3) exponential/default"
temp\$ = INPUT\$(1)
LOOP WHILE VAL(temp\$) < 1 AND VAL(temp\$) > 3
SELECT CASE temp\$
CASE "1"
CASE "2"
CASE "3"
END SELECT
GOTO main_start
END IF
END

playsong:
s("D5", 2) : s("G5", 3) : s("O", 1)
s("B5", 1) : s("G5", 1) : s("B5", 3) : s("O", 1)
s("A5", 2) : s("G5", 3) : s("O", 1)
s("E5", 2) : s("D5", 3) : s("O", 1)
s("D5", 2) : s("G5", 3) : s("O", 1)
s("B5", 1) : s("G5", 1) : s("B5", 3) : s("O", 1)
s("A5", 2) : s("D6", 5) : s("O", 1)
s("B5", 2) : s("D6", 3) : s("B5", 1) : s("D6", 1) : s("B5", 1) : s("G5", 3) : s("O", 1)
s("D5", 2) : s("E5", 3) : s("G5", 1) : s("G5", 1) : s("E5", 1) : s("D5", 3) : s("O", 1)
s("D5", 2) : s("G5", 3) : s("O", 1/4) : s("B5", 1) : s("B5", 1) : s("G5", 1) : s("B5", 3) : s("O", 1)
s("A5", 2) : s("G5", 3)
RETURN``````

## Hz#(note\$)

Charlie Veniot 27th December 2022 at 10:48pm

SetLocalStorageItem("sound A1", 55) SetLocalStorageItem("sound A1+", 58.270) SetLocalStorageItem("sound A1-", 51.913) SetLocalStorageItem("sound A2", 110) SetLocalStorageItem("sound A2+", 116.541) SetLocalStorageItem("sound A2-", 103.826) SetLocalStorageItem("sound A3", 220) SetLocalStorageItem("sound A3+", 233.082) SetLocalStorageItem("sound A3-", 207.652) SetLocalStorageItem("sound A4", 440) SetLocalStorageItem("sound A4+", 466.164) SetLocalStorageItem("sound A4-", 415.305) SetLocalStorageItem("sound A5", 880) SetLocalStorageItem("sound A5+", 932.328) SetLocalStorageItem("sound A5-", 830.609) SetLocalStorageItem("sound A6", 1760) SetLocalStorageItem("sound A6+", 1864.655) SetLocalStorageItem("sound A6-", 1661.219) SetLocalStorageItem("sound A7", 3520) SetLocalStorageItem("sound A7+", 3729.310) SetLocalStorageItem("sound A7-", 3322.438) SetLocalStorageItem("sound A8", 7040) SetLocalStorageItem("sound A8+", 7458.620) SetLocalStorageItem("sound A8-", 6644.875) SetLocalStorageItem("sound A9", 14080) SetLocalStorageItem("sound A9+", 14917.24) SetLocalStorageItem("sound A9-", 13289.75) SetLocalStorageItem("sound B1", 61.735) SetLocalStorageItem("sound B1-", 58.270) SetLocalStorageItem("sound B2", 123.471) SetLocalStorageItem("sound B2-", 116.541) SetLocalStorageItem("sound B3", 246.942) SetLocalStorageItem("sound B3-", 233.082) SetLocalStorageItem("sound B4", 493.883) SetLocalStorageItem("sound B4-", 466.164) SetLocalStorageItem("sound B5", 987.767) SetLocalStorageItem("sound B5-", 932.328) SetLocalStorageItem("sound B6", 1975.533) SetLocalStorageItem("sound B6-", 1864.655) SetLocalStorageItem("sound B7", 3951.066) SetLocalStorageItem("sound B7-", 3729.310) SetLocalStorageItem("sound B8", 7902.133) SetLocalStorageItem("sound B8-", 7458.620) SetLocalStorageItem("sound B9", 15804.266) SetLocalStorageItem("sound B9-", 14917.24) SetLocalStorageItem("sound C1", 32.703) SetLocalStorageItem("sound C1+", 34.648) SetLocalStorageItem("sound C2", 65.406) SetLocalStorageItem("sound C2+", 69.296) SetLocalStorageItem("sound C3", 130.813) SetLocalStorageItem("sound C3+", 138.591) SetLocalStorageItem("sound C4", 261.626) SetLocalStorageItem("sound C4+", 277.183) SetLocalStorageItem("sound C5", 523.251) SetLocalStorageItem("sound C5+", 554.365) SetLocalStorageItem("sound C6", 1046.502) SetLocalStorageItem("sound C6+", 1108.731) SetLocalStorageItem("sound C7", 2093.005) SetLocalStorageItem("sound C7+", 2217.461) SetLocalStorageItem("sound C8", 4186.009) SetLocalStorageItem("sound C8+", 4434.922) SetLocalStorageItem("sound C9", 8372.018) SetLocalStorageItem("sound C9+", 8869.844) SetLocalStorageItem("sound D1", 36.708) SetLocalStorageItem("sound D1+", 38.891) SetLocalStorageItem("sound D1-", 34.648) SetLocalStorageItem("sound D2", 73.416) SetLocalStorageItem("sound D2+", 77.782) SetLocalStorageItem("sound D2-", 69.296) SetLocalStorageItem("sound D3", 146.832) SetLocalStorageItem("sound D3+", 155.564) SetLocalStorageItem("sound D3-", 138.591) SetLocalStorageItem("sound D4", 293.665) SetLocalStorageItem("sound D4+", 311.127) SetLocalStorageItem("sound D4-", 277.183) SetLocalStorageItem("sound D5", 587.33) SetLocalStorageItem("sound D5+", 622.254) SetLocalStorageItem("sound D5-", 554.365) SetLocalStorageItem("sound D6", 1174.659) SetLocalStorageItem("sound D6+", 1244.508) SetLocalStorageItem("sound D6-", 1108.731) SetLocalStorageItem("sound D7", 2349.318) SetLocalStorageItem("sound D7+", 2489.016) SetLocalStorageItem("sound D7-", 2217.461) SetLocalStorageItem("sound D8", 4698.636) SetLocalStorageItem("sound D8+", 4978.032) SetLocalStorageItem("sound D8-", 4434.922) SetLocalStorageItem("sound D9", 9397.273) SetLocalStorageItem("sound D9+", 9956.063) SetLocalStorageItem("sound D9-", 8869.844) SetLocalStorageItem("sound E1", 41.203) SetLocalStorageItem("sound E1-", 38.891) SetLocalStorageItem("sound E2", 82.407) SetLocalStorageItem("sound E2-", 77.782) SetLocalStorageItem("sound E3", 164.814) SetLocalStorageItem("sound E3-", 155.564) SetLocalStorageItem("sound E4", 329.628) SetLocalStorageItem("sound E4-", 311.127) SetLocalStorageItem("sound E5", 659.255) SetLocalStorageItem("sound E5-", 622.254) SetLocalStorageItem("sound E6", 1318.51) SetLocalStorageItem("sound E6-", 1244.508) SetLocalStorageItem("sound E7", 2637.02) SetLocalStorageItem("sound E7-", 2489.016) SetLocalStorageItem("sound E8", 5274.041) SetLocalStorageItem("sound E8-", 4978.032) SetLocalStorageItem("sound E9", 10548.082) SetLocalStorageItem("sound E9-", 9956.063) SetLocalStorageItem("sound F1", 43.654) SetLocalStorageItem("sound F1+", 46.249) SetLocalStorageItem("sound F2", 87.307) SetLocalStorageItem("sound F2+", 92.499) SetLocalStorageItem("sound F3", 174.614) SetLocalStorageItem("sound F3+", 184.997) SetLocalStorageItem("sound F4", 349.228) SetLocalStorageItem("sound F4+", 369.994) SetLocalStorageItem("sound F5", 698.456) SetLocalStorageItem("sound F5+", 739.989) SetLocalStorageItem("sound F6", 1396.913) SetLocalStorageItem("sound F6+", 1479.978) SetLocalStorageItem("sound F7", 2793.826) SetLocalStorageItem("sound F7+", 2959.955) SetLocalStorageItem("sound F8", 5587.652) SetLocalStorageItem("sound F8+", 5919.911) SetLocalStorageItem("sound F9", 11175.303) SetLocalStorageItem("sound F9+", 11839.82) SetLocalStorageItem("sound G1", 48.999) SetLocalStorageItem("sound G1+", 51.913) SetLocalStorageItem("sound G1-", 46.249) SetLocalStorageItem("sound G2", 97.999) SetLocalStorageItem("sound G2+", 103.826) SetLocalStorageItem("sound G2-", 92.499) SetLocalStorageItem("sound G3", 195.998) SetLocalStorageItem("sound G3+", 207.652) SetLocalStorageItem("sound G3-", 184.997) SetLocalStorageItem("sound G4", 391.995) SetLocalStorageItem("sound G4+", 415.305) SetLocalStorageItem("sound G4-", 369.994) SetLocalStorageItem("sound G5", 783.991) SetLocalStorageItem("sound G5+", 830.609) SetLocalStorageItem("sound G5-", 739.989) SetLocalStorageItem("sound G6", 1567.982) SetLocalStorageItem("sound G6+", 1661.219) SetLocalStorageItem("sound G6-", 1479.978) SetLocalStorageItem("sound G7", 3135.963) SetLocalStorageItem("sound G7+", 3322.438) SetLocalStorageItem("sound G7-", 2959.955) SetLocalStorageItem("sound G8", 6271.927) SetLocalStorageItem("sound G8+", 6644.875) SetLocalStorageItem("sound G8-", 5919.911) SetLocalStorageItem("sound G9", 12543.854) SetLocalStorageItem("sound G9+", 13289.75) SetLocalStorageItem("sound G9-", 11839.82) SetLocalStorageItem("sound O", 0) ' function Hz#(note\$) note\$ = ucase\$(replace\$(note\$,"#","+")) note\$ = replace\$(note\$,"B+","C") Hz# = GetLocalStorageItem("sound " + note\$) end function