-
-
Save mwgamera/4654709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env es | |
# Morse code player for SoX and es. | |
# vim: ai ft=es.conf : | |
# config | |
wpm = $CWES_WPM 18; # signaling speed | |
freq = $CWES_FREQ 727; # carrier frequency | |
# lengths | |
u1 = `{dc <<< ($wpm(1) ' 9k1.200r/p')} | |
u3 = `{dc <<< ($u1 ' 3*p')} | |
u7 = `{dc <<< ($u1 ' 7*p')} | |
bw = `{dc <<< ($u1 ' 9k1r/7*p')} | |
# synth | |
dit = '| sox -n -p synth '^$u1^' sin '^$freq(1) | |
dah = '| sox -n -p synth '^$u3^' sin '^$freq(1) | |
spi = '| sox -n -p trim 0 '^$u1 | |
spl = '| sox -n -p trim 0 '^$u3 | |
spw = '| sox -n -p trim 0 '^$u7 | |
# insert inter-symbol spaces | |
fn isp * { | |
~ $#* 1 0 && return $* | |
let (s = (); i = 1) { | |
forever { | |
s = $s $*($#i) | |
i = 1 $i | |
~ $#* $#i && return $s $spi $*($#i) | |
s = $s $spi | |
} | |
} | |
} | |
# define sign | |
fn cwdef sym code { | |
let (ds = ()) { | |
for (s = <={%fsplit '' $code}) { | |
~ $s - && ds = $ds $dah | |
~ $s . && ds = $ds $dit | |
} | |
sym = ``(){tr '[:lower:]' '[:upper:]' <<< $^sym} | |
'_cwes_sym'^$^sym = <={isp $ds} | |
} | |
} | |
# letters | |
cwdef a .- | |
cwdef b -... | |
cwdef c -.-. | |
cwdef d -.. | |
cwdef e . | |
cwdef é ..-.. | |
cwdef f ..-. | |
cwdef g --. | |
cwdef h .... | |
cwdef i .. | |
cwdef j .--- | |
cwdef k -.- | |
cwdef l .-.. | |
cwdef m -- | |
cwdef n -. | |
cwdef o --- | |
cwdef p .--. | |
cwdef q --.- | |
cwdef r .-. | |
cwdef s ... | |
cwdef t - | |
cwdef u ..- | |
cwdef v ...- | |
cwdef w .-- | |
cwdef x -..- | |
cwdef y -.-- | |
cwdef z --.. | |
# figures | |
cwdef 1 .---- | |
cwdef 2 ..--- | |
cwdef 3 ...-- | |
cwdef 4 ....- | |
cwdef 5 ..... | |
cwdef 6 -.... | |
cwdef 7 --... | |
cwdef 8 ---.. | |
cwdef 9 ----. | |
cwdef 0 ----- | |
# punctuation and misc | |
cwdef '.' .-.-.- | |
cwdef ',' --..-- | |
cwdef ':' ---... | |
cwdef '?' ..--.. | |
cwdef '''' .----. | |
cwdef '-' -....- | |
cwdef '/' -..-. | |
cwdef '(' -.--. | |
cwdef ')' -.--.- | |
cwdef '"' .-..-. | |
cwdef '=' -...- | |
cwdef '+' .-.-. | |
cwdef '@' .--.-. | |
# build message and play it | |
message = $spi | |
let (sp = $spl) | |
for (x = <={%fsplit \1 ``\n{echo -- $* | tr '[:lower:]' '[:upper:]' | sed 's/./&'^\1^'/g'}}) { | |
~ $x '' && break | |
~ $x ' ' && message = $message $spw | |
~ $x '[' && sp = $spi # combined symbol, e.g. [SK] | |
~ $x ']' && sp = $spl | |
message = $message $('_cwes_sym' ^ $x) $sp | |
} | |
play -q $message bandpass $freq $bw gain -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment