Skip to content

Instantly share code, notes, and snippets.

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