Created
April 29, 2018 12:58
-
-
Save paavohuhtala/9eea7ec0ac190679cd4bf304718731e7 to your computer and use it in GitHub Desktop.
synthesis at https://acarabott.github.io/audio-dsp-playground/
This file contains 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
let time = 0; | |
function getSine(freq, time) { | |
const period = 2; | |
const phase = freq * (time % period); | |
return phase - Math.floor(phase); | |
//return Math.sin(2 * Math.PI * freq * time) > 0.5 ? 1 : 0.0; | |
} | |
function loop(numFrames, outL, outR, sampleRate) { | |
const freq = 40; | |
const amp = 0.1; | |
for (let i = 0; i < numFrames; i++) { | |
let sample = getSine(freq, time) * (amp / 2.0); | |
sample += getSine(freq * 1.002, time) * (amp / 2.0); | |
sample += getSine(freq * 0.998, time) * (amp / 2.0); | |
sample += getSine(freq * 1.004, time) * (amp / 2.0); | |
sample += getSine(freq * 0.996, time) * (amp / 2.0); | |
outL[i] = sample; | |
outR[i] = sample; | |
time += 1 / sampleRate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment