Skip to content

Instantly share code, notes, and snippets.

@notepadwebdev
notepadwebdev / speaker-cone-animations.js
Last active November 21, 2016 19:28
Animating speaker cone elements based on frequency bin volume data
// bin 3 : ~86 Hz
let percVol = this.dataArray[2] / 255;
TweenLite.to(this.wooferConeOuter, 0.001, {css:{scale: (1 + (percVol * 0.05)) }});
// bin 8 : ~301 Hz
percVol = this.dataArray[7] / 255;
TweenLite.to(this.wooferConeMid, 0.001, {css:{scale: (1 + (percVol * 0.1)) }});
// bin 17 : ~689 Hz
percVol = this.dataArray[16] / 255;
@notepadwebdev
notepadwebdev / speaker-cone.html
Last active November 21, 2016 19:17
Speaker cone mark up
<div class="cone">
<div class="cone-outer"></div>
<div class="cone-mid"></div>
<div class="cone-inner"></div>
</div>
@notepadwebdev
notepadwebdev / getByteFrequencyData.js
Last active November 21, 2016 19:17
Call analyser node getByteFrequencyData method
this.analyser.getByteFrequencyData(this.dataArray);
@notepadwebdev
notepadwebdev / onTick.js
Last active November 21, 2016 22:36
Recursive requestAnimationFrame loop
onTick() {
this.raf = requestAnimationFrame(this.onTick.bind(this));
this.analyser.getByteFrequencyData(this.dataArray);
// animations go here...
}
// Create Analyser
this.analyser = Pizzicato.context.createAnalyser();
this.analyser.fftSize = 1024;
this.bufferLength = this.analyser.frequencyBinCount;
this.dataArray = new Uint8Array(this.bufferLength);
this.LPF.connect(this.analyser);
@notepadwebdev
notepadwebdev / setPan.js
Last active November 21, 2016 19:16
Set the stereo panner position based on pageX position
// Set the stereo panner position based on pageX position
// pos value will be between -1 and 1
setPan(e) {
let pos = (((this.getEvent(e).pageX / $(window).width())*2)-1);
this.panner.pan = pos;
}
@notepadwebdev
notepadwebdev / setLPF.js
Last active November 21, 2016 19:15
Set the low pass filter based on pageY position
// Set the low pass filter based on pageY position
// freq value will be between 0 and 10,000
setLPF(e) {
let freq = 10000 - ((this.getEvent(e).pageY / $(window).height()) * 10000);
this.LPF.frequency = freq;
}
@notepadwebdev
notepadwebdev / event-handlers.js
Last active November 21, 2016 19:15
Event handlers for speaker interaction
// Event handlers
onTouchStart(e) {
e.preventDefault();
this.drumloop.play();
this.isPlaying = true;
}
onTouchEnd(e) {
this.drumloop.stop();
this.isPlaying = false;
@notepadwebdev
notepadwebdev / event-listeners.js
Last active November 21, 2016 19:14
Event listeners for speaker interaction
// Event Listeners
$('.speaker')
.on('touchstart mousedown', this.onTouchStart)
.on('touchmove mousemove', this.onTouchMove)
.on('touchend mouseup', this.onTouchEnd);
// Load the audio file for the loop
this.drumloop = new Pizzicato.Sound({
source: 'file',
options: {
path: '/assets/audio/drum-break-99bpm.wav',
loop: true
}
});
// Create the Low Pass Filter effect