Skip to content

Commit

Permalink
Merge pull request #24 from rocketinventor/master
Browse files Browse the repository at this point in the history
Updated song parser for JS
  • Loading branch information
fulldecent authored Oct 27, 2016
2 parents 71bf181 + 143532f commit 1874e2a
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 48 deletions.
35 changes: 32 additions & 3 deletions In Javascript/airgap.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,38 @@
<div class="content">
</br>
<input type="button" value="Play Song" onclick="start()"></br></br>
<textarea id="logs" style="width:70%;min-height:300px">Tested with Chrome at 1560Khz
</textarea>
<div style="font-size:14px">Ported by Yeo Quan Yang. Credits to the original author William Entriken @https://github.com/fulldecent</div><br/>
<textarea id="logs" style="width:70%;min-height:100px">Tested with Chrome at 1560Khz</textarea>
<p style="font-size:14px">Feel free to edit the code below or copy and paste any <em>valid</em> code.<br>Column one is time in <i>milliseconds</i>, and column two is <i>frequency</i>.</p>
<textarea id="tones" style="width:70%;min-height:200px">
400 2673
400 2349
400 2093
400 2349
400 2673
400 2673
790 2673
400 2349
400 2349
790 2349
400 2673
400 3136
790 3136
400 2673
400 2349
400 2093
400 2349
400 2673
400 2673
400 2673
400 2673
400 2349
400 2349
400 2673
400 2349
790 2093</textarea>
<div style="font-size:14px">Ported by <a href="https://github.com/quanyang">Yeo Quan Yang</a> & maintained by <a href="https://github.com/rocketinventor">Elliot Gerchak</a>.
<br>
Original machine code by <a href="https://github.com/fulldecent">William Entriken</a>.</div><br/>
<div style="font-size:14px">Project site at <a href="https://github.com/fulldecent/system-bus-radio">https://github.com/fulldecent/system-bus-radio</a></div><br/>
<div style="font-size:14px">List of computers that work and what frequency to try at <a href="https://github.com/fulldecent/system-bus-radio/blob/master/TEST-DATA.tsv">https://github.com/fulldecent/system-bus-radio/blob/master/TEST-DATA.tsv</a></div>
</div>
Expand Down
77 changes: 32 additions & 45 deletions In Javascript/airgap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,43 @@
//Tested to be working on Chrome at 1560khz

function now() {
return performance.now()*1000000;
return window.performance.now() * 1000000;
}

var NSEC_PER_SEC = 1000000000;
var register = 3.1415
var register = 3.1415;

function square_am_signal(time,freq) {
document.getElementById('logs').value += "Playing / "+time+" seconds / "+freq+"Hz\n";
var period = NSEC_PER_SEC/freq;
var start = now();
var end = now()+time*NSEC_PER_SEC;
while (now() < end) {
var mid = start+period/2;
var reset = start+period;
while (now()<mid) {
for (i = 0; i < 100; i++) {
register = 1 - Math.log(register) / 1.7193
}
}
while(now() < reset){
}
start = reset
}
function square_am_signal(time, freq) {
document.getElementById('logs').value += "Playing / " + time + " seconds / " + freq + "Hz\n";
var period = NSEC_PER_SEC / freq;
var start = now();
var end = now() + time * NSEC_PER_SEC;
while (now() < end) {
var mid = start + period / 2;
var reset = start + period;
while (now() < mid) {
for (var i = 0; i < 100; i++) {
register = 1 - Math.log(register) / 1.7193;
}
}
while (now() < reset) {}
start = reset;
}
}

function start() {
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2093);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2673);
square_am_signal(0.790, 2673);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2349);
square_am_signal(0.790, 2349);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 3136);
square_am_signal(0.790, 3136);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2093);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2349);
square_am_signal(0.400, 2673);
square_am_signal(0.400, 2349);
square_am_signal(0.790, 2093);
var song = document.getElementById("tones").value.split("\n");
var length = song.length;
var line, time, freq;
for (var i = 0; i < length; i++) {
line = song[i].split(" ");
if (line[1] == "0") {
// delay
}
else {
freq = +line[1];
time = +line[0];
square_am_signal(time, freq);
}
}
}
11 changes: 11 additions & 0 deletions In Javascript/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,15 @@ input[type="text"]:focus ,input[type="password"]:focus,textarea:focus,select:foc
input, textarea, keygen, select, button, isindex {
outline:none;
resize: none;
}
a
{
color: white;
font-weight:bold;
background-color: rgba(220, 220, 220, 0.35);
text-decoration:none;
}
a:hover
{
background-color: rgba(240, 240, 240, 0.52);
}
Loading

0 comments on commit 1874e2a

Please sign in to comment.