# CQ, a general call in International Morse code (ITU-R M.1677-1). No composer; the words are the arranger's. https://lab.glossema.dev/play/morse-cq/code # It plays the notes of https://lab.glossema.dev/play/morse-cq, tone for tone. # CQ calls all stations, DE means from, ROUTER is the station calling and K invites a reply. # One tone, F5 at 698 Hz, keyed on and off at 20 words per minute: a unit of 60 ms. # A dit sounds for one unit and a dah for three. The silence is one unit between the # signals of a letter, three between letters and seven between words. # The call goes out twice, with a pause between to listen for an answer. { :local call "CQ CQ DE ROUTER ROUTER K" # Each letter of the call in Morse code: a dot for a dit, a dash for a dah. :local morse {"C"="-.-."; "D"="-.."; "E"="."; "K"="-.-"; "O"="---"; "Q"="--.-"; "R"=".-."; "T"="-"; "U"="..-"} :local pitch 698 :local unit 60ms :local dit $unit :local dah ($unit * 3) :for pass from=1 to=2 do={ # Before the second call, listen for a reply: 34 units after the word space. :if ($pass = 2) do={ :delay ($unit * 34) } :local start 0 :while ($start < [:len $call]) do={ # A word runs up to the next space; a space after the call ends the last one. :local end [:find ($call . " ") " " $start] :local word [:pick $call $start $end] :put $word :for i from=0 to=([:len $word] - 1) do={ :local letter [:pick $word $i] :local code ($morse->$letter) :for j from=0 to=([:len $code] - 1) do={ :if ([:pick $code $j] = ".") do={ :beep frequency=$pitch length=$dit :delay $dit } else={ :beep frequency=$pitch length=$dah :delay $dah } # One unit of silence after every signal, :delay $unit } # two more after a letter, to make three, :delay ($unit * 2) } # and four more after a word, to make seven. :delay ($unit * 4) :set start ($end + 1) } } }