Skip to content

Instantly share code, notes, and snippets.

@miselaytes-anton
Created May 31, 2018 19:23
Show Gist options
  • Save miselaytes-anton/2d8cfaa79eb91735c3a7f4d10837c6e4 to your computer and use it in GitHub Desktop.
Save miselaytes-anton/2d8cfaa79eb91735c3a7f4d10837c6e4 to your computer and use it in GitHub Desktop.
const inputSignal = readSignalFromSomewhere()
const outputSignal = new Array(inputSignal.length)
const delayInSamples = 44100
const delayBuffer = new Array(delayInSamples)
const decay = 0.5
let pointer = 0
inputSignal.forEach(sample => {
const previousSample = delayBuffer[pointer % delayInSamples]
delayBuffer[pointer] = sample + previousSample * decay
//make sure out buffer is indeed circular
pointer++
if (pointer > delayInSamples){
pointer = 0;
}
outputSignal.push(sample + previousSample)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment