Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Karan Goel
481-SoundBrain
Commits
c765e480
Commit
c765e480
authored
Feb 27, 2015
by
Karan Goel
Browse files
make lights work, change instrument, make music work
parent
f5d86274
Changes
3
Hide whitespace changes
Inline
Side-by-side
webapp/_local_data_server.js
0 → 100644
View file @
c765e480
var
app
=
require
(
'
http
'
).
createServer
(
handler
)
var
io
=
require
(
'
socket.io
'
)(
app
);
var
fs
=
require
(
'
fs
'
);
app
.
listen
(
80
);
function
handler
(
req
,
res
)
{
res
.
writeHead
(
200
);
res
.
write
(
'
hi
'
);
res
.
end
();
}
var
this_socket
=
null
;
var
data
=
require
(
'
./data/record.json
'
);
var
i
=
0
;
function
sendData
()
{
this_socket
.
emit
(
'
brain
'
,
data
[
i
]
);
i
++
;
}
io
.
on
(
'
connection
'
,
function
(
socket
)
{
i
=
0
;
this_socket
=
socket
;
setInterval
(
sendData
,
500
);
});
\ No newline at end of file
webapp/brain.js
View file @
c765e480
...
...
@@ -223,7 +223,7 @@ function processPacket() {
++
payloadPointer
;
// TODO: move to multi byte code
connect_timer
=
null
;
clearInterval
(
connect_timer
)
;
switch
(
code
)
{
case
CODE_ATTENTION
:
...
...
webapp/index.html
View file @
c765e480
...
...
@@ -118,17 +118,6 @@ function sendAudioData(socket, data) {
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
();
var
PI
=
3.1415927
;
var
PI2
=
PI
*
2
;
var
tines
=
[];
var
lastSound
=
[];
var
data
=
[];
var
eegData
=
[];
// INITIALIZE WAVEFORM MAKERS
var
waveform
=
new
Waveform
({
...
...
@@ -207,19 +196,30 @@ var chart = new CanvasJS.Chart("eegWave", {
chart
.
render
();
var
nbrPoints
=
48
;
var
cycleLength
=
60
*
3
;
// 60*n minutes
var
startTime
=
(
new
Date
()).
getTime
();
var
PI
=
3.1415927
;
var
PI2
=
PI
*
2
;
var
tines
=
[];
var
lastSound
=
[];
var
data
=
[];
var
eegData
=
[];
// Instruments we support
var
instruments
=
[
"
acoustic_grand_piano
"
,
"
synth_drum
"
,
"
pad_2_warm
"
,
"
sitar
"
,
"
bright_acoustic_piano
"
"
bright_acoustic_piano
"
,
"
acoustic_bass
"
];
// Instrument that we play
var
instrument
=
0
;
var
instrument
=
3
;
var
relaySocket
;
// TODO: refactor
var
relaySocket
;
var
attention
=
0
;
var
meditation
=
0
;
RefreshFrame
=
function
()
{
...
...
@@ -232,12 +232,18 @@ RefreshFrame = function () {
if
(
Math
.
floor
(
a
/
PI2
)
!==
Math
.
floor
(
tines
[
i
]
/
PI2
))
{
delay
=
i
/
4
;
velocity
=
127
;
note
=
MIDI
.
pianoKeyOffset
+
meditation
;
sendLightData
(
relaySocket
,
"
red
"
,
Math
.
min
(
note
,
255
));
note
=
MIDI
.
pianoKeyOffset
;
if
(
attention
>
50
&&
meditation
>
50
)
{
note
+=
(
attention
+
meditation
)
/
2
;
}
else
if
(
attention
>
50
&&
meditation
<
50
)
{
note
+=
meditation
;
}
else
{
note
+=
attention
;
}
MIDI
.
noteOn
(
instrument
,
note
,
velocity
,
delay
);
lastSound
[
i
]
=
ms
;
data
.
push
(
Math
.
cos
(
note
));
...
...
@@ -264,8 +270,8 @@ var updateChart = function (attn, medit) {
});
// updating legend text with updated with y Value
chart
.
options
.
data
[
0
].
legendText
=
"
Attention
"
+
attn
;
chart
.
options
.
data
[
1
].
legendText
=
"
Meditation
"
+
medit
;
chart
.
options
.
data
[
0
].
legendText
=
"
Attention
"
+
attn
;
chart
.
options
.
data
[
1
].
legendText
=
"
Meditation
"
+
medit
;
chart
.
render
();
...
...
@@ -284,23 +290,19 @@ socket.on('get-EEG', function (data) {
var
min_data
=
0
;
var
max_data
=
100
;
attention
=
eeg_data
.
attention
;
meditation
=
eeg_data
.
meditation
;
nbrPoints
=
Math
.
round
(
min_nbrPoints
+
((
max_nbrPoints
-
min_nbrPoints
)
*
(
eeg_data
.
attention
-
min_data
))
/
(
max_data
-
min_data
));
nbrPoints
*=
0.5
;
updateChart
(
eeg_data
.
attention
,
eeg_data
.
meditation
);
RefreshFrame
();
// eegData.push(
Math.
cos
(eeg_data.attention));
// eegWaveform.update({
// data: eegData
// }
);
sendLightData
(
relaySocket
,
"
blue
"
,
Math
.
min
(
eeg_data
.
attention
,
255
));
sendLightData
(
relaySocket
,
"
red
"
,
Math
.
min
(
eeg_data
.
meditation
,
255
));
RefreshFrame
(
);
}
else
{
// eegData.push(Math.cos(90));
// eegWaveform.update({
// data: eegData
// });
console
.
log
(
'
Connecting...
'
)
}
});
...
...
@@ -319,10 +321,9 @@ window.onload = function () {
instruments
:
instruments
,
callback
:
function
()
{
MIDI
.
programChange
(
0
,
0
);
MIDI
.
programChange
(
1
,
118
);
MIDI
.
programChange
(
2
,
89
);
MIDI
.
programChange
(
3
,
104
);
MIDI
.
programChange
(
4
,
1
);
MIDI
.
programChange
(
1
,
104
);
MIDI
.
programChange
(
2
,
1
);
MIDI
.
programChange
(
3
,
32
);
MIDI_INITIALIZED
=
true
;
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment