Commit 40c3fe7c authored by Karan Goel's avatar Karan Goel
Browse files

sounds a bit melodic

parent 42a84e4a
......@@ -110,8 +110,8 @@ function sendAudioData(socket, data) {
// INITIALIZE CONSTANTS
var EEG_SOCKET_SERVER 'http://localhost:3000';
var AUDIO_SOCKET_SERVER 'ws://localhost:9000';
var EEG_SOCKET_SERVER = 'http://localhost:3000';
var AUDIO_SOCKET_SERVER = 'ws://localhost:9000';
var nbrPoints = 48;
var cycleLength = 60 * 3; // 60*n minutes
......@@ -172,7 +172,6 @@ RefreshFrame = function () {
note = MIDI.pianoKeyOffset + i;
MIDI.noteOn(instrument, note, velocity, delay);
MIDI.noteOn(0, note, velocity, delay);
lastSound[i] = ms;
......@@ -186,39 +185,41 @@ RefreshFrame = function () {
};
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...')
}
});
// var socket = io(EEG_SOCKET_SERVER);
// socket.on('connection', function() {
// 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...')
// }
// });
// });
// On web page is loaded:
window.onload = function () {
// Connect to relay server via web socket.
var relaySocket = new WebSocket(AUDIO_SOCKET_SERVER);
relaySocket.binaryType = "arraybuffer";
relaySocket.onopen = function(e) {
// var relaySocket = new WebSocket(AUDIO_SOCKET_SERVER);
// relaySocket.binaryType = "arraybuffer";
// relaySocket.onopen = function(e) {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
......@@ -232,12 +233,12 @@ window.onload = function () {
setInterval(RefreshFrame, 200);
},
callbackPCM: function (pcmBuffer) {
sendAudioData(relaySocket, pcmBuffer);
},
silent: false // Debug: remove to hear audio on system speaker
// callbackPCM: function (pcmBuffer) {
// sendAudioData(relaySocket, pcmBuffer);
// },
// silent: false // Debug: remove to hear audio on system speaker
});
};
// };
};
</script>
......
Supports Markdown
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