Published
Edited
Jul 31, 2019
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
main = {
const context = new AudioContext;
let dit = false;
let dash = false;
let wasDit = false;
let wasDash = false;
let timer;
const fsm = () => {
if (timer === undefined) {
if (wasDit || wasDash) {
const osc = context.createOscillator();
osc.type = 'sine';
osc.frequency.value = toneFreq;

const bpf = context.createBiquadFilter();
bpf.type = 'bandpass';
bpf.frequency.value = toneFreq;
bpf.Q.value = QValue;

const gain = context.createGain();
gain.gain.value = gainValue;

osc.connect(bpf)
bpf.connect(gain)
gain.connect(context.destination);

console.log('start ' + (wasDit ? '.' : '-'));
osc.start();
timer = setTimeout(() => {
osc.stop();
timer = setTimeout(() => {
timer = undefined;
wasDit |= dit;
wasDash |= dash;
fsm();
}, 1000 / toneRate);
}, (wasDit ? 1000 : 3000) / toneRate);
if (wasDash) {
wasDash = false;
} else {
wasDit = false;
}
}
}
};
document.onkeydown = event => {
console.log('down ' + event.key);
switch (event.key) {
case ditKey: dit = true; wasDit = true; break;
case dashKey: dash = true; wasDash = true; break;
}
fsm();
};

document.onkeyup = event => {
console.log('up ' + event.key);
switch (event.key) {
case ditKey: dit = false; break;
case dashKey: dash = false; wasDash = false; break;
}
fsm();
};
}
Insert cell
sleep = t => new Promise((resolve) => { setTimeout(resolve, t); })
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more