Ch07 - Chapter 7 Modifying Samples in a Range 1 Chapter Objectives 2 Knowing where we are in the sound More complex operations require us to know

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

View Full Document Right Arrow Icon
Chapter 7: Modifying Samples in a Range 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
Knowing where we are in the sound More complex operations require us to know where we are in the sound, which sample Not just process all the samples exactly the same Examples: Reversing a sound It’s just copying, like we did with pixels Changing the frequency of a sound Using sampling, like we did with pixels Splicing sounds 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
Using for to count with range >>> print range(1,3) [1, 2] >>> print range(3,1) [] >>> print range(-1,5) [-1, 0, 1, 2, 3, 4] >>> print range(1,100) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … 99] 4
Background image of page 4
Increasing volume by sample index def increaseVolumeByRange(sound): for sampleNumber in range(0, getLength (sound)): value = getSampleValueAt (sound, sampleNumber) setSampleValueAt (sound, sampleNumber, value * 2) def increaseVolume(sound): for sample in getSamples (sound): value = getSample (sample) setSample (sample,value * 2) This really is the same as: 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
Modify different sound sections The index lets us modify parts of the sound now - e.g. here we increase the volume in the first half, and then decrease it in the second half. def increaseAndDecrease(sound): length = getLength(sound) for index in range(0, length/2): value = getSampleValueAt(sound, index) setSampleValueAt(sound, index, value*2) for sampleIndex in range(length/2, length): value = getSampleValueAt(sound, index) setSampleValueAt(sound, index, value*0.2) 6
Background image of page 6
Array References Square brackets ([ ]) are standard notation for arrays (or lists). To access a single array element at position index , we use array[index] >>> myArray = range(0, 100) >>> print myArray[0] 0 >>> print myArray[1] 1 >>> print myArray[99] 99 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
Splicing Sounds Splicing gets its name from literally cutting and pasting pieces of magnetic tape together Doing it digitally is easy (in principle), but painstaking The easiest kind of splicing is when the component sounds are in separate files. All we need to do is copy each sound, in order, into a
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.

This note was uploaded on 02/23/2012 for the course CS 177 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 22

Ch07 - Chapter 7 Modifying Samples in a Range 1 Chapter Objectives 2 Knowing where we are in the sound More complex operations require us to know

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