Thursday, December 19, 2013

Reverse a Sound

def reverse (source):
  target = makeEmptySound (getLength(source), 44100)
  sourceIndex = 0
  for targetIndex in range (0, getLength(target)/2):
    sourceValue = getSampleValueAt (source, sourceIndex)
    setSampleValueAt (target, targetIndex, sourceValue)
    sourceIndex = sourceIndex + 1
  sourceIndex = getLength(source) -1
  for targetIndex in range (getLength(target)/2, getLength(target)):
    sourceValue = getSampleValueAt (source, sourceIndex)
    setSampleValueAt (target, targetIndex, sourceValue)
    sourceIndex = sourceIndex - 1
  return (target)

1 comment:

  1. Hey love your blog, wish I found it at the start of semester, probably for the best I didn't to be fair.

    ReplyDelete