Added comments to source code

This commit is contained in:
Elliot Gerchak 2016-11-27 05:51:16 +00:00
parent d935c28249
commit 958e5d4e23
2 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,9 @@
var player; var player; // Define "player" var to make my code linter happy
function start() { function start() { // Start Web Worker & send song data to player
var logs = document.getElementById('logs'); var logs = document.getElementById('logs'); // Define log element
// Create Web Worker if it doesn't already exist
if (window.Worker && typeof(player) == "undefined") { if (window.Worker && typeof(player) == "undefined") {
var player = new Worker("worker.js"); var player = new Worker("worker.js");
window.player = player; // Make variable Global window.player = player; // Make variable Global
@ -9,11 +11,13 @@ function start() {
var data = event.data; var data = event.data;
window.logs.value += data; window.logs.value += data;
}; };
// Send song data to player
var song = document.getElementById("tones").innerHTML; var song = document.getElementById("tones").innerHTML;
player.postMessage(song); player.postMessage(song);
} }
} }
function end() { function end() { // Stops the Web Worker
player.terminate(); player.terminate();
} }

View File

@ -11,7 +11,7 @@ function now() {
var NSEC_PER_SEC = 1000000000; var NSEC_PER_SEC = 1000000000;
var register = 3.1415; 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"); postMessage("\nPlaying / " + time + " seconds / " + freq + "Hz");
var period = NSEC_PER_SEC / freq; var period = NSEC_PER_SEC / freq;
var start = now(); 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"); song = song.split("\n");
var length = song.length; var length = song.length;
var line, time, freq; var line, time, freq;
@ -48,13 +48,13 @@ function play(song) {
close(); // Close Web Worker 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"); postMessage("\nPaused / " + time*.001 + " seconds");
var dt = new Date(); var dt = new Date();
while ((new Date()) - dt <= time) { /* Do nothing */ } while ((new Date()) - dt <= time) { /* Do nothing */ }
} }
onmessage = function(event) { onmessage = function(event) { // Recieve song data from main page
var data = event.data; var data = event.data;
play(data); play(data);
}; };