Skip to content

Instantly share code, notes, and snippets.

View kevincennis's full-sized avatar
💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
View GitHub Profile
// scale a value in range [f0,f1] to fit in [t0,t1]
scale = function( val, f0, f1, t0, t1 ){
return (val - f0) * (t1 - t0) / (f1 - f0) + t0;
};
@kevincennis
kevincennis / bounce.js
Created July 13, 2013 02:17
Bounce an AudioBuffer to WAV with RecorderWorker.js
// assuming you have an AudioBuffer instance called `buffer`,
// and an AudioContext (or OfflineAudioContext) called `ctx`...
// create a new Worker...
var worker = new Worker('recorderWorker.js');
// get it started and send some config data...
worker.postMessage({
command: 'init',
@kevincennis
kevincennis / whisper.js
Created July 19, 2013 00:38
Bookmarklet for calming down rants in all-caps
document.body.style.textTransform = 'lowercase';
@kevincennis
kevincennis / getusermedia.js
Created July 19, 2013 23:17
getUserMedia
var ctx = new webkitAudioContext();
navigator.webkitGetUserMedia({audio: true}, success, err);
function success( stream ) {
var src = ctx.createMediaStreamSource(stream);
src.connect(ctx.destination);
}
function err( e ) {
@kevincennis
kevincennis / pluck.js
Last active December 6, 2019 06:04
Karplus-Strong with Web Audio API
function Pluck( ctx ) {
this.sr = ctx.sampleRate;
this.pro = ctx.createScriptProcessor( 512, 0, 1 );
this.pro.connect( ctx.destination );
}
Pluck.prototype.play = function( freq ) {
var N = Math.round( this.sr / freq ),
impulse = this.sr / 1000,
y = new Float32Array( N ),
// see http://jsbin.com/okoxiq/3/edit
var src
, fftSize = 1024
, audio = new Audio()
, ac = new webkitAudioContext()
, analyser = ac.createAnalyser()
, timeData = new Uint8Array(fftSize)
, bar = document.querySelector('.bar')
, url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3';
@kevincennis
kevincennis / blankguide.js
Created August 26, 2013 14:57
Blank guide
var thirtymins = 1000 * 60 * 30,
advanced = 0;
Date.now = (function(){
var func = Date.now;
return function(){
return func() + advanced;
}
}());
@kevincennis
kevincennis / Scam.md
Last active December 26, 2015 17:29
Scam

Oct 24

Please contact me for a transaction. Claudia.

Oct 24

Oh, hello.

Oct 25

@kevincennis
kevincennis / flippinawesome.js
Created November 4, 2013 03:37
Better timing
var audio = new window.webkitAudioContext(),
position = 0,
scale = {
g: 392,
f: 349.23,
e: 329.63,
b: 493.88
},
song = "gfefgg-fff-gbb-gfefggggffgfe---";
@media print {
body * {
display: none !important;
}
body:after {
content: 'Seriously? A printer?';
}
}