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) { ...@@ -110,8 +110,8 @@ function sendAudioData(socket, data) {
// INITIALIZE CONSTANTS // INITIALIZE CONSTANTS
var EEG_SOCKET_SERVER 'http://localhost:3000'; var EEG_SOCKET_SERVER = 'http://localhost:3000';
var AUDIO_SOCKET_SERVER 'ws://localhost:9000'; var AUDIO_SOCKET_SERVER = 'ws://localhost:9000';
var nbrPoints = 48; var nbrPoints = 48;
var cycleLength = 60 * 3; // 60*n minutes var cycleLength = 60 * 3; // 60*n minutes
...@@ -172,11 +172,10 @@ RefreshFrame = function () { ...@@ -172,11 +172,10 @@ RefreshFrame = function () {
note = MIDI.pianoKeyOffset + i; note = MIDI.pianoKeyOffset + i;
MIDI.noteOn(instrument, note, velocity, delay); MIDI.noteOn(instrument, note, velocity, delay);
MIDI.noteOn(0, note, velocity, delay);
lastSound[i] = ms; lastSound[i] = ms;
data.push(Math.cos(i/25) - 0.2 + r*0.3); data.push(Math.cos(i/25) - 0.2 + r*0.3);
waveform.update({ waveform.update({
data: data data: data
}); });
...@@ -186,39 +185,41 @@ RefreshFrame = function () { ...@@ -186,39 +185,41 @@ RefreshFrame = function () {
}; };
var socket = io(EEG_SOCKET_SERVER); // var socket = io(EEG_SOCKET_SERVER);
socket.on('get-EEG', function (data) { // socket.on('connection', function() {
data = JSON.parse(data); // socket.on('get-EEG', function (data) {
// data = JSON.parse(data);
if (data.attention > 0 && data.meditation > 0) {
RefreshFrame(); // if (data.attention > 0 && data.meditation > 0) {
var min_nbrPoints = 48; // RefreshFrame();
var max_nbrPoints = 96; // var min_nbrPoints = 48;
var min_data = 0; // var max_nbrPoints = 96;
var max_data = 100; // var min_data = 0;
nbrPoints = min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (data.attention - min_data)) / (max_data - min_data); // 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({ // eegData.push(Math.cos(data.attention - 0.2 + 0.3));
data: eegData // eegWaveform.update({
}); // data: eegData
} else { // });
eegData.push(Math.cos(90)); // } else {
eegWaveform.update({ // eegData.push(Math.cos(90));
data: eegData // eegWaveform.update({
}); // data: eegData
console.log('Connecting...') // });
} // console.log('Connecting...')
}); // }
// });
// });
// On web page is loaded: // On web page is loaded:
window.onload = function () { window.onload = function () {
// Connect to relay server via web socket. // Connect to relay server via web socket.
var relaySocket = new WebSocket(AUDIO_SOCKET_SERVER); // var relaySocket = new WebSocket(AUDIO_SOCKET_SERVER);
relaySocket.binaryType = "arraybuffer"; // relaySocket.binaryType = "arraybuffer";
relaySocket.onopen = function(e) { // relaySocket.onopen = function(e) {
MIDI.loadPlugin({ MIDI.loadPlugin({
soundfontUrl: "./soundfont/", soundfontUrl: "./soundfont/",
...@@ -230,14 +231,14 @@ window.onload = function () { ...@@ -230,14 +231,14 @@ window.onload = function () {
MIDI.programChange(3, 104); MIDI.programChange(3, 104);
MIDI.programChange(4, 1); MIDI.programChange(4, 1);
setInterval(RefreshFrame, 200); 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> </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