rec9 - CS 177 Week 9 Recitation Slides Sound Combination,...

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

View Full Document Right Arrow Icon
1 CS 177 Week 9 Recitation Slides Sound Combination, Sampling and Building Bigger Programs
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ANY QUESTIONS?
Background image of page 2
3 Media File Path is Important >>> setMediaPath() #must be called before getMediaPath >>> 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)
Background image of page 3

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

View Full DocumentRight Arrow Icon
def double(source): len = getLength(source) / 2 + 1 target = makeEmptySound(len) targetIndex = 0 for sourceIndex in range(0, getLength( source), 2 ): value = getSampleValueAt( source, sourceIndex) setSampleValueAt( target, targetIndex, value) targetIndex = targetIndex + 1 play(target) return target Here’s the piece that does the doubling Why +1 here? 4
Background image of page 4
def half(source): target = makeEmptySound(getLength(source) * 2) sourceIndex = 0 for targetIndex in range(0, getLength( target)): value = getSampleValueAt( source, int (sourceIndex)) setSampleValueAt( target, targetIndex, value) sourceIndex = sourceIndex + 0.5 play(target) return target This is how a sampling synthesizer works! Here’s the piece that does the halving 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
Sampling as an Algorithm Think about the similarities between: Halving the sound’s frequency and scaling a picture larger. Doubling the sound’s frequency and scaling a picture smaller. 6
Background image of page 6
def half(filename): source = makeSound(filename) target = makeSound(filename) sourceIndex = 1 for targetIndex in range(1, getLength( target)+1): setSampleValueAt ( target, targetIndex,
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

rec9 - CS 177 Week 9 Recitation Slides Sound Combination,...

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

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