# 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 pages 1–9. Sign up to view the full content.

Chapter 7: Modifying Samples in a Range 1

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

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

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

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

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

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

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

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