Created
August 11, 2019 13:40
-
-
Save teropa/fb17f7b89c26c4e00bb164fe650b7b7e to your computer and use it in GitHub Desktop.
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
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