Skip to content

Instantly share code, notes, and snippets.

@teropa
Created August 11, 2019 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teropa/fb17f7b89c26c4e00bb164fe650b7b7e to your computer and use it in GitHub Desktop.
Save teropa/fb17f7b89c26c4e00bb164fe650b7b7e to your computer and use it in GitHub Desktop.
function peakNormalize(arr) {
let peakHigh = 0,
peakLow = 0;
for (let i = 0; i < arr.length; i++) {
peakHigh = Math.max(peakHigh, arr[i]);
peakLow = Math.min(peakLow, arr[i]);
}
if (peakHigh > 0.7 || peakLow < -0.7) {
let ratio = Math.max(peakHigh, -peakLow) / 0.7;
for (let i = 0; i < arr.length; i++) {
arr[i] /= ratio;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment