这是一堂课。教授要求我们合并两个不同长度的wav文件,如果前景文件长于背景,我们会被要求让前景继续循环,同时前景wav文件继续播放。我已经设法将它们组合在一起但是我为创建循环以继续播放的所有尝试都是徒劳的。也不允许任何模块。
def main():
#open and make fg "foreground" sound
openFileName = pickAFile()
fgsound = makeSound (openFileName)
#open and make bg "background" sound
openFileName2 = pickAFile()
bgsound = makeSound (openFileName2)
finalsound = combineSounds (fgsound, bgsound)
explore (finalsound)
def combineSounds(fgsound, bgsound):
sampleList1 = getSamples(fgsound)
sampleList2 = getSamples (bgsound)
fglength = getLength (fgsound)
bglength = getLength (bgsound)
for i in range(fglength):
amp1 = getSampleValue (sampleList1[i])
amp2 = getSampleValue (sampleList2[i])
amp2 = ((amp2)/3)
if amp2 > bglength:
amp2 = (bglength * i) - amp2
amp3 = amp1 + amp2
if (amp3 > 32767):
amp3 = 32767
elif (amp3 < -32768):
amp3 = -32768
setSampleValue (sampleList1[i], amp3)