# HG changeset patch # User Nicholas Jillings # Date 1425817825 0 # Node ID d7d1aa6d355864ae4593a44adc21cfc5bc12f688 # Parent 3156674c7bb33bd11a88b28242d81a9d0b9f9ea9 Added intial files. apeTool.html is main index html document to be loaded. core.js contains core functions and classes including audioEngine and audioObjects. graphics.css and structure.css for css style definitions. diff -r 3156674c7bb3 -r d7d1aa6d3558 apeTool.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apeTool.html Sun Mar 08 12:30:25 2015 +0000 @@ -0,0 +1,31 @@ + + + + + + + + + apeTool + + + + + + + + + + + + + + + + +
+

HTML5 APE Tool

+
+ + diff -r 3156674c7bb3 -r d7d1aa6d3558 core.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.js Sun Mar 08 12:30:25 2015 +0000 @@ -0,0 +1,114 @@ +/** + * core.js + * + * Main script to run, calls all other core functions and manages loading/store to backend. + * Also contains all global variables. + */ + +/* create the web audio API context and store in audioContext*/ +var audioContext; + +var audioEngineContext; + +window.onload = function() { + // Function called once the browser has loaded all files. + // This should perform any initial commands such as structure / loading documents + + // Create a web audio API context + // NORE: Currently this will only work with webkit browsers (Chrome/Safari)! + audioContext = new webkitAudioContext; + + // Create the audio engine object + audioEngineContext = new AudioEngine(); +} + +function loadProjectSpec(url) { + // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data + // If url is null, request client to upload project XML document +} + +function createProjectSave(destURL) { + // Save the data from interface into XML and send to destURL + // If destURL is null then download XML in client +} + +function AudioEngine() { + + // Create two output paths, the main outputGain and fooGain. + // Output gain is default to 1 and any items for playback route here + // Foo gain is used for analysis to ensure paths get processed, but are not heard + // because web audio will optimise and any route which does not go to the destination gets ignored. + this.outputGain = audioContext.createGain(); + this.fooGain = audioContext.createGain(); + this.fooGain.gain = 0; + + // Connect both gains to output + this.outputGain.connect(audioContext.destination); + this.fooGain.connect(audioContext.destination); + + // Create store for new audioObjects + this.audioObjects = []; + + this.play = function() { + // Send play command to all playback buffers for synchronised start + // Also start timer callbacks to detect if playback has finished + } + + this.stop = function() { + // Send stop and reset command to all playback buffers + } + + this.newTrack = function(url) { + // Pull data from given URL into new audio buffer + // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' + var request = new XMLHttpRequest(); + request.open('GET',url,true); + request.responseType = 'arraybuffer'; + // Create the audioObject with ID of the new track length; + audioObjectId = this.audioObjects.length + this.audioObjects[audioObjectId] = new audioObject(audioObjectId); + + // Create callback to decode the data asynchronously + request.onload = function() { + audioContext.decodeAudioData(request.response, function(decodedData) { + audioObj = audioEngineContext.audioObjects[audioObjectId]; + audioObj.buffer = decodedData; + audioObj.bufferNode.buffer = audioObj.buffer; + audioObj.state = 1; + }, console.log("Err - Buffer not added to " + audioObjectId)); + } + request.send(); + } + +} + +function audioObject(id) { + // The main buffer object with common control nodes to the AudioEngine + + this.id = id; + this.state = 0; // 0 - no data, 1 - ready + + // Create a buffer and external gain control to allow internal patching of effects and volume leveling. + this.bufferNode = audioContext.createBufferSource(); + this.outputGain = audioContext.createGain(); + + // Connect buffer to the audio graph + this.bufferNode.connect(this.outputGain); + this.outputGain.connect(audioEngineContext.outputGain); + + // the audiobuffer is not designed for multi-start playback + // When stopeed, the buffer node is deleted and recreated with the stored buffer. + this.buffer; + + this.play = function(startTime) { + this.bufferNode.start(startTime); + } + + this.stop = function() { + this.bufferNode.stop(0); + this.bufferNode = audioContext.createBufferSource(); + this.bufferNode.connect(this.outputGain); + this.bufferNode.buffer = this.buffer; + } + +} diff -r 3156674c7bb3 -r d7d1aa6d3558 graphics.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graphics.css Sun Mar 08 12:30:25 2015 +0000 @@ -0,0 +1,7 @@ +/* graphics.css + * Define colours and effects for classes and objects + */ + +body { + +} diff -r 3156674c7bb3 -r d7d1aa6d3558 structure.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/structure.css Sun Mar 08 12:30:25 2015 +0000 @@ -0,0 +1,7 @@ +/* structure.css + * Define the structure for classes and objects in HTML + */ + +body { + +}