2016-03-04 18:41:03 +01:00
|
|
|
//Credits to https://github.com/fulldecent/system-bus-radio
|
|
|
|
//As well as Jordan Harband for the nodejs simd library
|
|
|
|
//Tested to be working on Chrome at 1560khz
|
|
|
|
|
|
|
|
function now() {
|
2016-03-08 06:26:40 +01:00
|
|
|
return window.performance.now() * 1000000;
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var NSEC_PER_SEC = 1000000000;
|
2016-03-08 05:58:24 +01:00
|
|
|
var register = 3.1415;
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-03-08 06:26:40 +01:00
|
|
|
function square_am_signal(time, freq) {
|
|
|
|
document.getElementById('logs').value += "Playing / " + time + " seconds / " + freq + "Hz\n";
|
|
|
|
var period = NSEC_PER_SEC / freq;
|
2016-03-08 05:58:24 +01:00
|
|
|
var start = now();
|
2016-03-08 06:26:40 +01:00
|
|
|
var end = now() + time * NSEC_PER_SEC;
|
2016-03-08 05:58:24 +01:00
|
|
|
while (now() < end) {
|
2016-03-08 06:26:40 +01:00
|
|
|
var mid = start + period / 2;
|
|
|
|
var reset = start + period;
|
|
|
|
while (now() < mid) {
|
2016-03-08 05:58:24 +01:00
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
register = 1 - Math.log(register) / 1.7193;
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 06:26:40 +01:00
|
|
|
while (now() < reset) {}
|
2016-03-08 05:58:24 +01:00
|
|
|
start = reset;
|
|
|
|
}
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
2016-10-27 00:33:22 +02:00
|
|
|
var song = document.getElementById("tones").value.split("\n");
|
2016-03-08 06:20:38 +01:00
|
|
|
var length = song.length;
|
2016-10-27 00:33:22 +02:00
|
|
|
var line, time, freq;
|
|
|
|
for (var i = 0; i < length; i++) {
|
2016-03-08 06:20:38 +01:00
|
|
|
line = song[i].split(" ");
|
2016-10-27 00:33:22 +02:00
|
|
|
if (line[1] == "0") {
|
2016-03-08 06:20:38 +01:00
|
|
|
// delay
|
|
|
|
}
|
2016-10-27 00:33:22 +02:00
|
|
|
else {
|
|
|
|
freq = +line[1];
|
|
|
|
time = +line[0];
|
|
|
|
square_am_signal(time, freq);
|
2016-03-08 06:20:38 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|