New song format

Changed over the song parser and accompanying code to be inline with the new, as suggested in issue #28.
This commit is contained in:
Elliot Gerchak 2016-10-26 22:33:22 +00:00
parent 81756689ba
commit a0637721ce
2 changed files with 35 additions and 40 deletions

View File

@ -17,34 +17,34 @@
</br>
<input type="button" value="Play Song" onclick="start()"></br></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">
Feel free to edit the code below. Just make sure you keep to the format that it's in and have all of the punctuation.
:beep frequency=2673 length=400;
:beep frequency=2349 length=400;
:beep frequency=2093 length=400;
:beep frequency=2349 length=400;
:beep frequency=2673 length=400;
:beep frequency=2673 length=400;
:beep frequency=2673 length=790;
:beep frequency=2349 length=400;
:beep frequency=2349 length=400;
:beep frequency=2349 length=790;
:beep frequency=2673 length=400;
:beep frequency=3136 length=400;
:beep frequency=3136 length=790;
:beep frequency=2673 length=400;
:beep frequency=2349 length=400;
:beep frequency=2093 length=400;
:beep frequency=2349 length=400;
:beep frequency=2673 length=400;
:beep frequency=2673 length=400;
:beep frequency=2673 length=400;
:beep frequency=2673 length=400;
:beep frequency=2349 length=400;
:beep frequency=2349 length=400;
:beep frequency=2673 length=400;
:beep frequency=2349 length=400;
:beep frequency=2093 length=790;</textarea>
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 Yeo Quan Yang. Credits to the original author William Entriken @https://github.com/fulldecent</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>

View File

@ -28,23 +28,18 @@ function square_am_signal(time, freq) {
}
function start() {
var song = document.getElementById("tones").value.split(":");
var song = document.getElementById("tones").value.split("\n");
var length = song.length;
var i = 1,
line, time, freq;
while (1 <= length) {
var line, time, freq;
for (var i = 0; i < length; i++) {
line = song[i].split(" ");
if (line[0] == "beep") {
freq = +line[0].split("=")[1];
time = +line[2].split("=")[1].slice(0, -1);
square_am_signal(time, freq);
}
if (line[0] == "delay") {
if (line[1] == "0") {
// delay
}
if (song[i] == "end") {
i = 1;
else {
freq = +line[1];
time = +line[0];
square_am_signal(time, freq);
}
i++;
}
}