Permalink
Browse files

add cat sounds

  • Loading branch information...
maxogden committed Sep 6, 2012
1 parent 296c4be commit 12c604af08975036562287aacd533ea238cfef9b
View
Binary file not shown.
View
Binary file not shown.
View
@@ -16,6 +16,9 @@
<body>
<audio id="kick" src="kick.wav"></audio>
<audio id="ding" src="ding.wav"></audio>
+ <audio id="catmeow" src="catmeow.wav"></audio>
+ <audio id="meow" src="meow.wav"></audio>
+ <audio id="basso" src="basso.wav"></audio>
<audio id="snare" src="snare.wav"></audio>
<audio id="hihat" src="hihat.wav"></audio>
<audio id="clap" src="clap.wav"></audio>
View
@@ -8,10 +8,10 @@ catch(err){
var socket = io.connect('http://localhost:8000')
var sounds = {
- 0: document.querySelector('#ding'),
+ 0: document.querySelector('#catmeow'),
1: document.querySelector('#snare'),
- 2: document.querySelector('#hihat'),
- 3: document.querySelector('#clap')
+ 2: document.querySelector('#kick'),
+ 3: document.querySelector('#meow')
}
socket.on('hit', function(hit) {
View
Binary file not shown.
View
@@ -1,28 +1,94 @@
var http = require('http')
var socketio = require('socket.io')
var fs = require('fs')
-var tpad = require('../../lib/tpad')
-var color = require('color')
var ecstatic = require('ecstatic')(__dirname)
-
-tpad.init(function (err, tpad) {
- var enabled = {0: true, 1: true, 2: true, 3: true}
- tpad.each(function(pad, index) {
- pad.on('pressure', function(p) {
- console.log(p.value)
- if (p.value === 0) return enabled[index] = true
- if (!enabled[index]) return
- enabled[index] = false
- io.sockets.emit('hit', {pad: index, value: p.value})
- })
- })
-})
-
+var tpad = require('../../lib/tpad')
+ , color = require('color')
+ ;
+
var server = http.createServer(function(req, res) {
if (req.url.match(/socket\.io/)) return
ecstatic(req, res)
})
var io = socketio.listen(server)
io.set('log level', 1)
console.log('Listening on :8000')
-server.listen(8000)
+server.listen(8000)
+
+
+tpad.init(function (err, tpad) {
+ function initStats() {
+ return {
+ 0: {values: [], last: 0},
+ 1: {values: [], last: 0},
+ 2: {values: [], last: 0},
+ 3: {values: [], last: 0}
+ }
+ }
+
+ var padstats = initStats()
+
+ function average(ary) {
+ var sum = 0
+ for (var i = 0; i < ary.length; i++) {
+ sum += parseInt(ary[i])
+ }
+ return sum/(ary.length)
+ }
+
+ function difference(num1, num2) {
+ num1 = Math.abs(num1)
+ num2 = Math.abs(num2)
+ return (num1 > num2) ? num1 - num2 : num2 - num1
+ }
+
+ function translate(n, sourceLow, sourceHigh, targetLow, targetHigh) {
+ return (n - sourceLow) / (sourceHigh - sourceLow) * (targetHigh - targetLow) + targetLow
+ }
+
+ var bucketsize = 5
+ var colorchangethreshhold = 5
+ var lowerpressure = 2000
+ var upperpressure = 18000
+ var lastTouch
+
+ tpad.each(function(pad, index) {
+
+ setInterval(function() {
+ if ( (new Date() - lastTouch) > 200 ) {
+ pad.color('#609FFF')
+ padstats = initStats()
+ }
+ }, 199)
+
+ pad.on('pressure', function(p) {
+ lastTouch = new Date()
+ var bucket = padstats[p.index]
+ if (bucket.values.length > bucketsize) bucket.values.pop()
+ if (p.value < lowerpressure) p.value = lowerpressure
+ if (p.value > upperpressure) p .value = upperpressure
+ var num = translate(p.value, lowerpressure, upperpressure, 0, 255)
+ num = Math.floor(num)
+ bucket.values.unshift(num)
+ var avg = Math.floor(average(bucket.values))
+ var val = bucket.last
+ if (difference(avg, bucket.last) > colorchangethreshhold) val = avg
+ var c = color({r: val, g: 255 - val, b: 255})
+ if (val === 0) return
+ else console.log(val, c.hexString())
+ p.color(c.hexString())
+ bucket.last = val
+ console.log("SEND", index, val)
+ io.sockets.emit('hit', {pad: index, value: val})
+ });
+
+ pad.on('depress', function(p) {
+ padstats = initStats()
+ });
+
+ });
+
+});
+
+
+

0 comments on commit 12c604a

Please sign in to comment.