Write a function that will input two sounds. Create a new sound with one half of the first sound, then add the two sounds together for the length of the two sounds, and then add the second half of the second sound. This is easiest to do if the sounds have the same length.
Note: While this is easiest to do if the sounds have the same length, the function below can handle sounds of different lengths via the two if statements in the mid loop. However, this is not required to answer this question. Additionally, the question does not specify how to “add” the two sounds together, which means an answer could just add both values together. To avoid something too loud, the function below blends the two
sounds, but this is not a requirement.
```
def addSounds(sound ,sound2):
maxLength = max(getLength(sound), getLength(sound2))
canvas=makeEmptySound(getLength(sound)/2+getLength(sound2)/2+maxLength)
for index in range(0, getLength(sound)/2):
soundSample = getSampleValueAt(sound,index)
setSampleValueAt(canvas ,index ,soundSample)
for index in range (0 ,maxLength):
soundSample = 0
if index
sound2Sample = 0
if index
newSample = 0.5* soundSample + 0.5* sound2Sample
setSampleValueAt(canvas ,index+getLength(sound)/2,newSample)
for index in range (0 ,getLength(sound2)/2):
sound2Sample = getSampleValueAt(sound2,index)
setSampleValueAt(canvas ,(index+getLength(sound)/2+maxLength),sound2Sample)
play(canvas)
return canvas
```
You might also like to view...
What is the octal number system? How many digits are used in the octal number system?
What will be an ideal response?
Display course description, total capacity and number of sections in each course, where there is more than 1 section. (18 rows)
What will be an ideal response?
Which of the following is not true about TrueType fonts?
A) They must be downloaded from the Web. B) They print smoothly at any point size. C) They are scalable. D) They are supported by Windows.
Your organization decides to use digital signatures to sign messages. Which security tenets are covered by this implementation?
A. confidentiality B. authentication C. nonrepudiation D. integrity E. options a and b only F. options c and d only G. options b, c, and d only