Created
October 22, 2017 20:48
-
-
Save beefchimi/6b5967fa9994c4c44b3ea0043caeb8c1 to your computer and use it in GitHub Desktop.
Function for distorting an audio input
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
export default function distortionCurve(amount = 0) { | |
const sampleRate = 44100; | |
const curve = new Float32Array(sampleRate); | |
const deg = Math.PI / 180; | |
for (let i = 0; i < sampleRate; ++i) { | |
const x = (i * 2 / sampleRate) - 1; | |
curve[i] = ( | |
( | |
(3 + amount) * x * 20 * deg | |
) / ( | |
(amount * Math.abs(x)) + Math.PI | |
) | |
); | |
} | |
return curve; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment