From 958e5d4e2394085c006bb6f42d9cbd5e7373d318 Mon Sep 17 00:00:00 2001 From: Elliot Gerchak Date: Sun, 27 Nov 2016 05:51:16 +0000 Subject: [PATCH] Added comments to source code --- In Javascript/airgap.js | 12 ++++++++---- In Javascript/worker.js | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/In Javascript/airgap.js b/In Javascript/airgap.js index f65a32c..93b1f69 100644 --- a/In Javascript/airgap.js +++ b/In Javascript/airgap.js @@ -1,7 +1,9 @@ -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 @@ -9,11 +11,13 @@ function start() { 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(); } diff --git a/In Javascript/worker.js b/In Javascript/worker.js index 8c4524d..89ad9ab 100644 --- a/In Javascript/worker.js +++ b/In Javascript/worker.js @@ -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(); @@ -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; @@ -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); }; \ No newline at end of file