Last active
August 29, 2015 14:02
-
-
Save lambda-fairy/68626ee4ef648dcc79ce to your computer and use it in GitHub Desktop.
Playing around with wavepot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll just leave this here....
var speed = 120000002;
AND
var speed = 160000002;