Created
September 15, 2016 16:12
-
-
Save timhuff/526a2538ce84b20a7ce8b594eb2d1c9e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
numBars = 73 | |
bars = [0..numBars-1].map -> 0 | |
getDisplayBars = (audioData)-> | |
deltaT = audioData.length/numBars | |
bars[0] = audioData[0] | |
for barNum in [1..numBars-1] | |
timeIndex = barNum*deltaT | |
leftIndex = Math.floor timeIndex | |
rightIndex = Math.ceil timeIndex | |
leftWeight = timeIndex%1 | |
rightWeight = 1-leftWeight | |
leftValue = audioData[leftIndex] | |
rightValue = audioData[rightIndex] | |
bars[barNum] = leftValue*leftWeight + rightValue*rightWeight | |
bars | |
# set audioData to an array of random values between -1 and 1 | |
audioData = [0..99].map -> Math.random()*2-1 | |
getDisplayBars audioData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment