Skip to content

Commit

Permalink
Added comments to source code
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketinventor committed Nov 27, 2016
1 parent d935c28 commit 958e5d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions In Javascript/airgap.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
var player;
var player; // Define "player" var to make my code linter happy

function start() {
var logs = document.getElementById('logs');
function start() { // Start Web Worker & send song data to player
var logs = document.getElementById('logs'); // Define log element

// Create Web Worker if it doesn't already exist
if (window.Worker && typeof(player) == "undefined") {
var player = new Worker("worker.js");
window.player = player; // Make variable Global
player.onmessage = function(event) {
var data = event.data;
window.logs.value += data;
};

// Send song data to player
var song = document.getElementById("tones").innerHTML;
player.postMessage(song);
}
}

function end() {
function end() { // Stops the Web Worker
player.terminate();
}
8 changes: 4 additions & 4 deletions In Javascript/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function now() {
var NSEC_PER_SEC = 1000000000;
var register = 3.1415;

function square_am_signal(time, freq) {
function square_am_signal(time, freq) { // This funcion generates the radio waves
postMessage("\nPlaying / " + time + " seconds / " + freq + "Hz");
var period = NSEC_PER_SEC / freq;
var start = now();
Expand All @@ -29,7 +29,7 @@ function square_am_signal(time, freq) {
}
}

function play(song) {
function play(song) { // Parse song data, and call on required scripts to run it
song = song.split("\n");
var length = song.length;
var line, time, freq;
Expand All @@ -48,13 +48,13 @@ function play(song) {
close(); // Close Web Worker
}

function pause(time) {
function pause(time) { // A useless function to run when there is no noise to play
postMessage("\nPaused / " + time*.001 + " seconds");
var dt = new Date();
while ((new Date()) - dt <= time) { /* Do nothing */ }
}

onmessage = function(event) {
onmessage = function(event) { // Recieve song data from main page
var data = event.data;
play(data);
};

0 comments on commit 958e5d4

Please sign in to comment.