Powershell, 120120 117 bytes
[Console]::beep
, note labels and frequencies inspired by Iszi
($a='ccggaaGffeeddC')+'ggffeeD'*2+$a|% t*y|%{[console]::beep((0,440110,0,26265,29473,33082,34987,39298)[$_-band7]band7]*4,600+600*($_-lt97))}
Main idea:
- The melody is encoded in a string.
- The notes are encoded with chars
A
,C
,D
,E
,F
,G
. - Uppercase means a
double duration
. - 3 lower bits (
$_-band7
) of each note uses as index in the frequencies array (A->1
,C->3
,D->4
...) in - This script uses the reduced sampling rate for frequencies array:
(0,110,0,65,73,82,87,98)[$_-band7]*4
instead Iszi's(0,440,0,262,294,330,349,392)[$_-band7]
.[console]::Beep
is not the most accurate musical instrument, so it can slightly fake :)
Explanation: For each char from the melody string ccggaaGffeeddCggffeeDggffeeDccggaaGffeeddC
, the script:
- lookups frequensies from the array using the lower bits as index
- calculates a duration based on char uppercase/lowercase
- callcalls
[console]::beep
to play the note