Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save lambda-fairy/68626ee4ef648dcc79ce to your computer and use it in GitHub Desktop.

Select an option

Save lambda-fairy/68626ee4ef648dcc79ce to your computer and use it in GitHub Desktop.
Playing around with wavepot
// lfairy - go away
Array.prototype.sum = function() {
return this.reduce(function(a, b) { return a + b; }, 0);
};
function dsp(t) {
var base = Math.floor(t) % 2 ? 261.63 : 220;
var wave = [base, 3/2 * base, 4/3 * base, 5/2 * base].map(function(freq) { return 0.1 * sub(sin(freq, t), 1, t); }).sum();
var drone = [110, 440, 880].map(function(freq) { return 0.1 * sin(freq, t); }).sum();
return wave + (1 + sin(1/8, t)) / 2 * drone;
}
var TAU = 2 * Math.PI;
function sin(freq, t) {
return Math.sin(TAU * t * freq);
}
function saw(freq, t) {
return t * freq % 2 - 1;
}
function sqr(freq, t) {
return Math.floor(t * freq % 2) ? -1 : 1;
}
function sub(wave, mul, t){
return Math.sin(wave * mul + TAU * t);
}
// lfairy - quasiphone
var speed = 4;
var tenor = [-5, 0, 4, 0, -3, 0, 4, 0];
var alto = [0, 4, 7, 4, 0, 4, 7, 4];
function dsp(t) {
var m = Math.floor(t * speed);
var wave1 = 0.5 * quasiphone(pitch(tenor[m % tenor.length]), m / speed, t);
var wave2 = 0.5 * quasiphone(pitch(alto[m % alto.length]), m / speed, t);
return wave1 + wave2;
}
function quasiphone(freq, s, t) {
return damp((4 * sin(freq, t) + sin(1.99*freq, t) + sin(2.01*freq, t) + sin(3.01*freq, t)) / 7, 8, t - s);
}
function pitch(x) {
// Middle C is 0
return 261.63 * Math.pow(2, x/12);
}
var TAU = 2 * Math.PI;
function sin(freq, t) {
return Math.sin(TAU * t * freq);
}
function damp(wave, a, t) {
return Math.exp(-a * t) * wave;
}
@Chase-san
Copy link
Copy Markdown

I'll just leave this here....

var speed = 120000002;

AND

var speed = 160000002;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment