Commit 42a84e4a authored by Karan Goel's avatar Karan Goel
Browse files

remove unneeded files. add new testing code

parent 640f55b4
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- midi.js package -->
<script src="./js/MIDI/AudioDetect.js" type="text/javascript"></script>
<script src="./js/MIDI/LoadPlugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Plugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Player.js" type="text/javascript"></script>
<script src="./js/Window/DOMLoader.XMLHttp.js" type="text/javascript"></script>
<!-- extras -->
<script src="./inc/Base64.js" type="text/javascript"></script>
<script src="./inc/base64binary.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "acoustic_grand_piano",
callback: function() {
var delay = 0; // play one note every quarter second
var note = 50; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 0.75);
}
});
};
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- midi.js package -->
<script src="./js/MIDI/AudioDetect.js" type="text/javascript"></script>
<script src="./js/MIDI/LoadPlugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Plugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Player.js" type="text/javascript"></script>
<script src="./js/Window/DOMLoader.XMLHttp.js" type="text/javascript"></script>
<!-- extras -->
<script src="./inc/Base64.js" type="text/javascript"></script>
<script src="./inc/base64binary.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
// For debug purpose only.
function array2str(ua) {
var h = '';
for (var i = 0; i < ua.length; i++) {
h += "\\0x" + ua[i].toString(16);
}
return h;
}
// Utilities for sending light data over a web socket.
function sendLightData(socket, color, brightness) {
if (brightness < 0 || brightness > 255) {
throw new Error('Brightness must be between 0 and 255 (inclusive)');
}
var outputBuffer;
if (color == "red") {
outputBuffer = new Uint8Array([0x01, brightness]);
} else if (color == "blue") {
outputBuffer = new Uint8Array([0x02, brightness]);
} else {
throw new Error('Color must be \'red\' or \'blue\'');
}
socket.send(outputBuffer);
}
// Utilities for sending audio data over a web socket.
function float32To16bitPCM(input) {
var output = new Int16Array(input.length);
for (var i = 0; i < input.length; ++i) {
var sample = input[i]; //saturation: Math.max(-1, Math.min(1, buffer[l]));
output[i] = (sample < 0) ? (sample * 0x8000) : (sample * 0x7FFF);
}
return output.buffer;
}
function concatBuffers(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
}
function sendAudioData(socket, data) {
var pcmBuffer = float32To16bitPCM(data);
var header = new Uint8Array([0x00]);
var outputBuffer = concatBuffers(header.buffer, pcmBuffer);
socket.send(outputBuffer);
}
// On web page is loaded:
window.onload = function () {
// Connect to relay server via web socket.
var relaySocket = new WebSocket('ws://localhost:9000');
relaySocket.binaryType = "arraybuffer";
relaySocket.onopen = function(e) {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instruments: [ "acoustic_grand_piano", "synth_drum" ],
callback: function() {
MIDI.programChange(0, 0);
MIDI.programChange(1, 118);
for (var n = 0; n < 100; n ++) {
var delay = n / 4; // play one note every quarter second
var note = MIDI.pianoKeyOffset + n; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.noteOn(0, note, velocity, delay);
// play the some note 3-steps up
MIDI.noteOn(1, note + 3, velocity, delay);
}
},
callbackPCM: function (pcmBuffer) {
sendAudioData(relaySocket, pcmBuffer);
},
silent: true // Debug: remove to hear audio on system speaker
});
};
};
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Custom Music Box</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- midi.js package -->
<script src="./js/Color/SpaceW3.js" type="text/javascript"></script>
<script src="./js/MIDI/AudioDetect.js" type="text/javascript"></script>
<script src="./js/MIDI/LoadPlugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Plugin.js" type="text/javascript"></script>
<script src="./js/MIDI/Player.js" type="text/javascript"></script>
<script src="./js/MusicTheory/Synesthesia.js" type="text/javascript"></script>
<script src="./js/Widgets/Loader.js" type="text/javascript"></script>
<script src="./js/Window/Event.js" type="text/javascript"></script>
<script src="./js/Window/DOMLoader.XMLHttp.js" type="text/javascript"></script>
<script src="./js/waveform.js"></script>
<!-- extras -->
<script src="./inc/Base64.js" type="text/javascript"></script>
<script src="./inc/base64binary.js" type="text/javascript"></script>
<script src="./js/waveform.js"></script>
<script src="https://cdn.socket.io/socket.io-1.3.2.js"></script>
<!-- font -->
<link href="http://fonts.googleapis.com/css?family=Andada" rel="stylesheet" type="text/css" />
<style>
body {
background: #000; color: #fff; font-family: andada; line-height: 1.5em;
}
#wave {
width: 100%;
height: 200px;
margin-bottom: 30px;
position: absolute;
top: 10%;
/*transform: translateY(-150px);*/
}
#eegWave {
width: 100%;
height: 200px;
margin-bottom: 30px;
position: absolute;
top: 60%;
/*transform: translateY(150px);*/
}
h1 {
color: #fff;
}
</style>
</head>
<style type="text/css">
#wave {
width: 100%;
height: 200px;
margin-bottom: 30px;
position: absolute;
top: 10%;
}
#eegWave {
width: 100%;
height: 200px;
margin-bottom: 30px;
position: absolute;
top: 60%;
}
h1 {
color: #fff;
}
</style>
<body>
<div id="wave">
<h1>Soundwave</h1>
</div>
<div id="wave">
<h1>Soundwave</h1>
</div>
<div id="eegWave">
<h1>EEG Data: (Attention)</h1>
</div>
<div id="eegWave">
<h1>EEG Data: (Attention)</h1>
</div>
<script type="text/javascript">
// For debug purpose only.
function array2str(ua) {
var h = '';
for (var i = 0; i < ua.length; i++) {
h += "\\0x" + ua[i].toString(16);
}
return h;
}
// Utilities for sending light data over a web socket.
function sendLightData(socket, color, brightness) {
if (brightness < 0 || brightness > 255) {
throw new Error('Brightness must be between 0 and 255 (inclusive)');
}
var outputBuffer;
if (color == "red") {
outputBuffer = new Uint8Array([0x01, brightness]);
} else if (color == "blue") {
outputBuffer = new Uint8Array([0x02, brightness]);
} else {
throw new Error('Color must be \'red\' or \'blue\'');
}
socket.send(outputBuffer);
}
// Utilities for sending audio data over a web socket.
function float32To16bitPCM(input) {
var output = new Int16Array(input.length);
for (var i = 0; i < input.length; ++i) {
var sample = input[i]; //saturation: Math.max(-1, Math.min(1, buffer[l]));
output[i] = (sample < 0) ? (sample * 0x8000) : (sample * 0x7FFF);
}
return output.buffer;
}
function concatBuffers(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
}
function sendAudioData(socket, data) {
var pcmBuffer = float32To16bitPCM(data);
var header = new Uint8Array([0x00]);
var outputBuffer = concatBuffers(header.buffer, pcmBuffer);
socket.send(outputBuffer);
}
// INITIALIZE CONSTANTS
var EEG_SOCKET_SERVER 'http://localhost:3000';
var AUDIO_SOCKET_SERVER 'ws://localhost:9000';
var nbrPoints = 48;
var cycleLength = 60 * 3; // 60*n minutes
var startTime = (new Date()).getTime();
......@@ -75,108 +125,121 @@ var data = [];
var eegData = [];
// INITIALIZE WAVEFORM MAKERS
var waveform = new Waveform({
container: document.getElementById("wave"),
interpolate: false
});
var ctx = waveform.context;
var gradient = ctx.createLinearGradient(0, 0, 0, waveform.height);
gradient.addColorStop(0.0, "#f60");
gradient.addColorStop(1.0, "#ff1b00");
waveform.innerColor = gradient;
var eegWaveform = new Waveform({
container: document.getElementById("eegWave"),
interpolate: false
});
var ctx2 = eegWaveform.context;
var gradient2 = ctx2.createLinearGradient(0, 0, 0, eegWaveform.height);
gradient2.addColorStop(0.0, "#ff6");
gradient2.addColorStop(1.0, "#fff");
eegWaveform.innerColor = gradient2;
// Instruments we support
var instruments = [
"acoustic_grand_piano",
"synth_drum",
"pad_2_warm",
"sitar",
"bright_acoustic_piano"
];
// Instrument that we play
var instrument = 4;
RefreshFrame = function () {
var speed = (PI2 * nbrPoints) / cycleLength;
var ms = (new Date()).getTime();
var timer = (ms - startTime) * .001 * speed;
for (var i = 0; i < nbrPoints; ++i) {
var r = (i + 1) / nbrPoints;
var a = timer * r;
if (Math.floor(a / PI2) !== Math.floor(tines[i] / PI2)) {
delay = i / 4;
velocity = 127;
note = MIDI.pianoKeyOffset + i;
MIDI.noteOn(instrument, note, velocity, delay);
MIDI.noteOn(0, note, velocity, delay);
lastSound[i] = ms;
data.push(Math.cos(i/25) - 0.2 + r*0.3);
waveform.update({
data: data
});
}
tines[i] = a;
}
var speed = (PI2 * nbrPoints) / cycleLength;
var ms = (new Date()).getTime();
var timer = (ms - startTime) * .001 * speed;
for (var i = 0; i < nbrPoints; ++i) {
var r = (i + 1) / nbrPoints;
var a = timer * r;
if (Math.floor(a / PI2) !== Math.floor(tines[i] / PI2)) {
delay = i / 4;
velocity = 127;
note = MIDI.pianoKeyOffset + i;
MIDI.noteOn(instrument, note, velocity, delay);
MIDI.noteOn(0, note, velocity, delay);
lastSound[i] = ms;
data.push(Math.cos(i/25) - 0.2 + r*0.3);
waveform.update({
data: data
});
}
tines[i] = a;
}
};
var socket = io('http://localhost:3000');
var socket = io(EEG_SOCKET_SERVER);
socket.on('get-EEG', function (data) {
data = JSON.parse(data);
if (data.attention > 0 && data.meditation > 0) {
RefreshFrame();
var min_nbrPoints = 48;
var max_nbrPoints = 96;
var min_data = 0;
var max_data = 100;
nbrPoints = min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (data.attention - min_data)) / (max_data - min_data);
eegData.push(Math.cos(data.attention - 0.2 + 0.3));
eegWaveform.update({
data: eegData
});
} else {
eegData.push(Math.cos(90));
eegWaveform.update({
data: eegData
});
console.log('Connecting...')
}
data = JSON.parse(data);
if (data.attention > 0 && data.meditation > 0) {
RefreshFrame();
var min_nbrPoints = 48;
var max_nbrPoints = 96;
var min_data = 0;
var max_data = 100;
nbrPoints = min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (data.attention - min_data)) / (max_data - min_data);
eegData.push(Math.cos(data.attention - 0.2 + 0.3));
eegWaveform.update({
data: eegData
});
} else {
eegData.push(Math.cos(90));
eegWaveform.update({
data: eegData
});
console.log('Connecting...')
}
});
// On web page is loaded:
window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instruments: [
"acoustic_grand_piano",
"synth_drum",
"pad_2_warm",
"sitar",
"bright_acoustic_piano"
],
callback: function() {
MIDI.programChange(0, 0);
MIDI.programChange(1, 118);
MIDI.programChange(2, 89);
MIDI.programChange(3, 104);
MIDI.programChange(4, 1);
// setInterval(RefreshFrame, 200);
}
});
};
// Connect to relay server via web socket.
var relaySocket = new WebSocket(AUDIO_SOCKET_SERVER);
relaySocket.binaryType = "arraybuffer";
relaySocket.onopen = function(e) {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instruments: instruments,
callback: function() {
MIDI.programChange(0, 0);
MIDI.programChange(1, 118);
MIDI.programChange(2, 89);
MIDI.programChange(3, 104);
MIDI.programChange(4, 1);
setInterval(RefreshFrame, 200);
},
callbackPCM: function (pcmBuffer) {
sendAudioData(relaySocket, pcmBuffer);
},
silent: false // Debug: remove to hear audio on system speaker
});
};
};
</script>
</body>
</html>
\ No newline at end of file
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment