Write a function that interleaves two sounds. It starts with 2 seconds of the first sound and then 2 seconds of the second sound. Then it continues with the next 2 seconds of the first sound and the next 2 seconds of the second sound and so on until both sounds have been fully copied to the target sound.

For this answer, one cannot assume the two sounds will be the same length, or that they’ll go evenly into 2 second chunks, therefore it’s necessary to check whether one sound has already been “used up” in order to avoid a run time error.

```
def interleaveSounds(sound, sound2):
target = makeEmptySound(getLength(sound) + getLength(sound2))
targetSamples = getSamples(target)
soundSamples = getSamples(sound)
soundIndex = 0
sound2Samples = getSamples(sound2)
sound2Index = 0

sectionLength = int(getSamplingRate(target)*2)

for index in range(0, getLength(target)):
section = int(index)/sectionLength
if section %2==0:
if soundIndex sourceValue = getSampleValue(soundSamples[soundIndex])
setSampleValue(targetSamples[index] ,sourceValue)

soundIndex = soundIndex+1
elif sound2Index sourceValue = getSampleValue(sound2Samples[sound2Index])
setSampleValue(targetSamples[index] ,sourceValue)

sound2Index = sound2Index+1
else:
if sound2Index sourceValue = getSampleValue(sound2Samples[sound2Index])
setSampleValue(targetSamples[index] ,sourceValue)

sound2Index = sound2Index+1
elif soundIndex sourceValue = getSampleValue(soundSamples[soundIndex])
setSampleValue(targetSamples[index] ,sourceValue)

soundIndex = soundIndex+1

return target
```

Computer Science & Information Technology

You might also like to view...

Which of the following is NOT a tab in Access 2013?

A) Create B) Home C) Format D) File

Computer Science & Information Technology

When in Slide Master view, the first slide image in the thumbnail pane represents the ________

A) slide design style B) content and layout format C) Office Theme title slide D) Office Theme Slide Master

Computer Science & Information Technology