ch08 - Chapter 8: Making Sounds by Combining Pieces 1...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 8: Making Sounds by Combining Pieces 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter Objectives 2
Background image of page 2
Making more complex sounds We know that natural sounds are often the combination of multiple sounds. Adding waves in physics or math is hard. In computer science, it’s easy! Simply add the samples at the same index in the two waves: for srcSample in range(0, getLength (source)): destValue= getSampleValueAt (dest, srcSample) srcValue= getSampleValueAt (source, srcSample) setSampleValueAt (source, srcSample, srcValue+destValue) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Adding sounds The first two are sine waves. The third is just the sum of the first two columns. a b a + b = c 4
Background image of page 4
Uses for adding sounds We can mix sounds We even know how to change the volumes of the two sounds, even over time (e.g., fading in or fading out) We can create echoes We can add sine (or other) waves together to create kinds of instruments/sounds that do not physically exist, but which sound interesting and complex 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A function for adding two sounds def addSoundInto(sound1, sound2): for sampleNmr in range(0, getLength (sound1)): sample1 = getSampleValueAt (sound1, sampleNmr) sample2 = getSampleValueAt (sound2, sampleNmr) setSampleValueAt (sound2, sampleNmr, sample1 + sample2) Notice that this adds sound1 and sound2 by adding sound1 into sound2 6
Background image of page 6
Making a chord by mixing three notes >>> c4=makeSound(getMediaPath("bassoon-c4.wav")) >>> e4=makeSound(getMediaPath("bassoon-e4.wav")) >>> g4=makeSound(getMediaPath("bassoon-g4.wav")) >>> addSoundInto(e4,c4) >>> play(c4) >>> addSoundInto(g4,c4) >>> play(c4) 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
def makeChord(sound1, sound2, sound3): for index in range(0, getLength (sound1)): s1Sample = getSampleValueAt (sound1, index) setSampleValueAt (sound1, index, s1Sample ) if index > 1000: s2Sample = getSampleValueAt (sound2, index - 1000) setSampleValueAt (sound1, index, s1Sample + s2Sample) if index > 2000: s3Sample = getSampleValueAt (sound3, index - 2000) setSampleValueAt (sound1, index, s1Sample + s2Sample + s3Sample) -Add in sound2 after 1000 samples -Add in sound3 after 2000 samples Note that in this version we’re adding into sound1! 8
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

ch08 - Chapter 8: Making Sounds by Combining Pieces 1...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online