Created
October 22, 2017 20:48
Function for distorting an audio input
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
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