Skip to content

Instantly share code, notes, and snippets.

@timhuff
Created September 15, 2016 16:12
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 timhuff/526a2538ce84b20a7ce8b594eb2d1c9e to your computer and use it in GitHub Desktop.
Save timhuff/526a2538ce84b20a7ce8b594eb2d1c9e to your computer and use it in GitHub Desktop.
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