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
setSampleValue(targetSamples[index] ,sourceValue)
soundIndex = soundIndex+1
elif sound2Index
setSampleValue(targetSamples[index] ,sourceValue)
sound2Index = sound2Index+1
else:
if sound2Index
setSampleValue(targetSamples[index] ,sourceValue)
sound2Index = sound2Index+1
elif soundIndex
setSampleValue(targetSamples[index] ,sourceValue)
soundIndex = soundIndex+1
return target
```
You might also like to view...
The ____ function is essentially on the front-lines of personnel security when it is auditing the performance of the controls in the personnel security operation.
A. auditing B. certification C. accountability D. compliance
Which of the following statements is true about this line?
Consider the following line of code. ``` Comparable s = new String(); ``` a) It will result in a compile-time error. b) It will result in a run-time error. c) It will create a String object pointed to by a Comparable reference. d) Although it is perfectly valid Java, it should be avoided due to confusion. e) none of the above are true
Which of the following is false?
a. Since BigInteger is not a primitive type, we can’t use the arithmetic, relational and equality operators with BigIntegers. b. BigInteger method compareTo compares the BigInteger number that calls the method to the method’s BigInteger argument, and returns -1 if the BigInteger that calls the method is less than the argument, 0 if they’re equal or 1 if the BigInteger that calls the method is greater than the argument. c. The value 1 can be implicitly converted to a BigInteger. d. BigInteger can represent integer values larger than what primitive type long can represent.
What process is required to avoid wasting memory if successive calls to the pop method on a list are made?
A. delete the array B. grow the array C. reset the array D. shrink the array