feature: add sounds to realtime signal page (#342)

This commit is contained in:
dman776 2019-01-28 23:39:51 -06:00 committed by GitHub
parent 07aa305e29
commit d9acfa2ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 4 deletions

View File

@ -155,6 +155,7 @@ $header = <<EOF;
dps[0].push(result[0][0]);
chart.render();
var snr = (result[0][0].y[1] * -1) - (result[0][0].y[0] * -1);
toneFreq(snr);
\$('#snr').html(snr);
});
};
@ -170,6 +171,33 @@ $header = <<EOF;
}
chart.render();
}); // --- document.ready
var audioCtx = new(window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
oscillator.type = 'sine';
gainNode.connect(audioCtx.destination);
gainNode.gain.value = 1;
function toneFreq(snr) {
oscillator.frequency.value = snr * 20;
}
function toneOn() {
oscillator = audioCtx.createOscillator();
gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
oscillator.type = 'sine';
gainNode.connect(audioCtx.destination);
gainNode.gain.value = 1;
oscillator.start();
};
function toneOff() {
oscillator.stop();
};
</script>
</head>
EOF
@ -229,12 +257,11 @@ $page = $page . "<input type='hidden' name='realtime' value='1'></input>\n" if($
$page = $page . <<EOF;
</form>
</div>
<div id="snrValues">
<h2>
<div id="snrValues" style="float: left;">
EOF
$page = $page . "SNR: <span id='snr'>0</span>dB" if($parms{"realtime"} eq "1");
$page = $page . "<div><h3>SNR: <span id='snr'>0</span>dB</h3></div>" if($parms{"realtime"} eq "1");
$page = $page . "<div style='float: right;'>Sound: <button onclick='toneOn();'>On</button>&nbsp;<button onclick='toneOff();'>Off</button></div>" if($parms{"realtime"} eq "1");
$page = $page . <<EOF;
</h2>
</div>
<div id="chartContainer" style="width: 80%; height: 60%;"></div>
</center>