In this mini-lab you will gain practice with using the techniques of mirroring, adding, and blending sounds.
copySoundInto function. Fill in the following
code skeleton to create function that combines two sounds end to end.
def appendSound(sound1, sound2): # Make an empty sound long enough to contain both source sounds. # Copy sound1 into the beginning of the new sound using copySoundInto. # Copy sound2 into the end of the new sound using copySoundInto. # Return the new sound.
appendSound function. You may use the backwards
function given below instead of writing your own.
Fill in the missing sections of code below. You may use the backwards
function given below instead of writing your own.
# Mirror entire sound (new sound is original sound # followed by backwards original sound) def mirrorEntireSound(sound): # Reverse the original sound # Append sound and reverseSound # Return the mirrored sound
backwards, which has been modified to take a sound as a
parameter instead of a filename, into JES to use.
def backwards(source):
numSamples = getNumSamples(source)
target = makeEmptySoundFromNumSamples(numSamples)
# Go backwards through source and write into target
sourceIndex = getLength(source)
for targetIndex in range(1, getLength(source)+1):
sourceValue = getSampleValueAt(source, sourceIndex)
setSampleValueAt(target, targetIndex, sourceValue)
sourceIndex = sourceIndex - 1
return target
# Add sound1 to sound2
# return the resulting sound
def addSounds(sound1, sound2):
# Determine which sound has minimum length
# Create a new sound of that length
for index in range( , ):
# Get the appropriate sample values from each sound
# Add the sample values together
# Set the sample value at this index in newSound to be the new value
# Blend two sounds
def blendSounds(sound1, sound2, overlapAmt):
# Get the lengths (# of samples) in each sound
length1 =
length2 =
# Make an empty sound large enough to hold the new sound
totalNumSamples =
newSound =
# Copy first sound up to the overlap section
# Add the overlap section
for index in range( , ):
value1 =
value2 =
newValue =
setSampleValueAt( )
# Copy the rest of sound2
# return the new sound