Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Spring 2003: Manipulate an array #2

Try the problem here from Sp 2003 Midterm Review #1

def dup100(sound):
  for sampleIndex in range(1,100):
    value=getSampleValueAt(sound,sampleIndex)
    print value, value
  for sampleIndex in range(101,200):
    value=getSampleValueAt(sound,sampleIndex)
    print value

okay, so this generates something (which I hope are the samples). However, I wasn't sure what to print exactly. The problem said that the first 100 should print twice, and the second 100 only once, but it didn't say how much of the sound to print. Clarification, maybe?
Lauren Biddle



Lauren, I got your program to work. I believe that he just wants the first 200 samples to be duplicates of the first 100 (just like his example in the problem). It doesn't say anything on the problem about another 100. He says, "..first 200 samples will be different from the original...but the rest of the samples will be the same [as the original]." I believe your program does what he's asking for. That's my thoughts.
Rebecca Phillips

Not quite. Did you see my example in class yesterday? The goal is to change the input sound. Note, too, that the input is a filename, not a sound. You'll have to generate a source and target sound from the filename, then copy samples one-for-two from the source into the target. Mark Guzdial


Will we need to do this?

here is what i got from class... i am confused about what is being asked here...
def dup100(file):
source=makeSound(file)
target=makeSound(file)
for pos in range(1,101):
setSampleValueAt(target,(pos-1)2+1,getSampleValueAt(source,pos))
setSampleValueAt(target,(pos-1)2+2,getSampleValueAt(source,pos))
return target

and it didnt indent... indent after :s

We didn't cover this example until this monday, will it still be fair game for the exam??


No, I already said that I wouldn't put something like this on the midterm. Mark Guzdial


sweet

Thank you!



For any one still interested, let me know what you think of this:

def dup100(file):
  source = makeSound(file)
  target = makeSound(file)

  sourceIndex = 1
  for targetIndex in range(1,200):
    set SampleValueAt(target, targetIndex, getSampleValueAt(source, int(sourceIndex)))
    sourceIndex = sourceIndex + 0.5

  sourceIndex = 101
  for targetIndex in range(201,getLength(source)+101):
    set SampleValueAt(target, targetIndex, getSampleValueAt(source, sourceIndex))
    sourceIndex = sourceIndex + 1

  play (target)
  return target




Chip Lay


Nice job, Chip! (Get rid of the space between "set" and "SampleValueAt.") I don't think you need that second loop, though. In fact, when you reference the targetIndex at getLength(source)+1, you're going to get an ArrayOutOfBoundsException. Mark Guzdial




Link to this Page