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

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

1 CS 177 Week 9 Recitation Slides Sound Combination, Sampling and Building Bigger Programs

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

View Full Document
2 ANY QUESTIONS?
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)

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

View Full Document
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
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

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

View Full Document
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
def half(filename): source = makeSound(filename) target = makeSound(filename) sourceIndex = 1 for targetIndex in range(1, getLength( target)+1): setSampleValueAt ( target, targetIndex,

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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
Ask a homework question - tutors are online