Skip to content

Instantly share code, notes, and snippets.

@nick-thompson
Created October 29, 2012 06:04
Show Gist options
  • Save nick-thompson/3971849 to your computer and use it in GitHub Desktop.
Save nick-thompson/3971849 to your computer and use it in GitHub Desktop.
Audio buffer processing functions
# Returns a reversed copy of the supplied sample buffer
reverse = (buffer) ->
data = buffer.getChannelData 0
ret = audioContext.createBuffer 1, data.length, 44100
retData = ret.getChannelData 0
i = 0
j = data.length
retData[i++] = data[j] while j--
ret
# Returns a copy of the supplied sample buffer where the first chunk of
# the original buffer is copied repeatedly into the return buffer.
glitch = (buffer, size) ->
data = buffer.getChannelData 0
len = Math.floor(data.length / size)
slice = data.subarray 0, len
newBuffer = audioContext.createBuffer 1, data.length, 44100
newData = newBuffer.getChannelData 0
newData.set slice, (len * i) for i in [0..(size - 1)]
newBuffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment